我想将File保存到客户端。怎么做? 当我启动服务器localy一切都很好文件保存@需要的地方,当在服务器上运行然后文件保存在服务器端:(。因为System.getProperty(“user.home”)正在返回:/ root。 用户从系统中选择文件并想要打开它。代码示例:
mylog.pl("Blob in use + stop counter:" + stop);
File file = new File(SU.userHome + "/" + fileName);
mylog.pl("File maked ! Path:" + file.getAbsolutePath());
in = blob.getBinaryStream();
out = new FileOutputStream(file);
byte[] buff = new byte[4096];
int len = 0;
while ((len = in.read(buff)) != -1) {
out.write(buff, 0, len);
}
try {
mylog.pl("Desktop Open!");
if (Desktop.isDesktopSupported())
{
Desktop.getDesktop().open(file);
}
else
{
mylog.pl("Desktop is not suported!");
//For other IS
DesktopApi.open(file);
}
}
catch (Exception e) {
mylog.pl("err @ runtime" + e.getMessage());
}
谢谢!保证正确的答案!
答案 0 :(得分:0)
//From server to client
final FileResource res = new FileResource(file);
FileDownloader fd = new FileDownloader(res);
p.open(res, "MyWindow", false);
file.delete();