0

I am working on an application in which I need to open attachments. I need to click on the "Open" button and open a pdf file. The way I do it, is by getting the content from the Server and writing it to a location on the temp directory.

However when I try to access this service from a remote machine, http://myserverIP:port/openMyAttachment, it accesses the temp directory of myserverIP instead of the local machine. It then opens the file on myserverIP.

I am using the following code to get the temp directory:

    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;

Can someone please share your thoughts? How can I get to access the temp directory on teh local machine and write the file to the local machine?

skaffman
  • 398,947
  • 96
  • 818
  • 769
SSM
  • 45
  • 1
  • 10

1 Answers1

1

You're trying to do too much on the server. If you have a Java program running locally, then it should be showing the JFileChooser, then fetching the file, writing it to a local temp space, and displaying it. The only thing the server should do is provide an InputStream to get the file contents from. If you change your server to have a getAttachment query (or something) instead of the openMyAttachment query that just serves back a pdf file. Then you should be able to fetch it with a URLConnection and complete the work on the local computer.

Always Learning
  • 5,510
  • 2
  • 17
  • 34
  • Thanks for the response. new JFileChooser() is now throwing a null pointer exception. Any ideas why? – SSM Sep 10 '15 at 22:06
  • Can you show how the code looks now? Just calling `new JFileChooser()` should not cause an NPE. – Always Learning Sep 16 '15 at 13:57
  • Thanks for your response Steve. The code is the same as above. We did not proceed further and now we will start working on this module again. The problem is after fetching the tmp variable a null pointer exception is thrown. – SSM Sep 17 '15 at 21:00
  • The code in the original post could not throw an NPE in the second line. Do you dump a stack trace and the line number it's thrown on is the FileChooser call and there are no parameters? – Always Learning Sep 22 '15 at 18:15