我正在开发一个需要打开附件的应用程序。我需要单击“打开”按钮并打开一个 pdf 文件。我这样做的方式是从服务器获取内容并将其写入临时目录上的某个位置。
但是,当我尝试从远程机器 http://myserverIP:port/openMyAttachment访问此服务时,它会访问 myserverIP 的临时目录而不是本地机器。然后它会打开 myserverIP 上的文件。
我正在使用以下代码来获取临时目录:
String tmp = System.getProperty("java.io.tmpdir");
JFileChooser fc = new JFileChooser();
FileSystemView fsv = fc.getFileSystemView();
File f = fsv.getDefaultDirectory();
String dir = f.getAbsolutePath();
String strDirectory = "temp~" + f.separator;
有人可以分享你的想法吗?如何访问本地机器上的临时目录并将文件写入本地机器?