0

When a file is opened in internet explorer without saving, it stores the file in temp folder. In windows 10 it creates a folder with random name in temp folder. I need to read the file using java. But java file api requires me to give the path of the file to read the contents of the file. How can I get the exact location of the file with the name that is stored by ie?

I tried using the java.io.tmpdir but it doesn't refer to the folder where the file is stored.

BufferedReader br = new BufferedReader(new FileReader(path to the file));
try {
    StringBuilder sb = new StringBuilder();
    String line = br.readLine();

    while (line != null) {
        sb.append(line);
        sb.append(System.lineSeparator());
        line = br.readLine();
    }
    String everything = sb.toString();
} finally {
    br.close();
}

I expect exact file name and the path to the file location.

Joakim Danielson
  • 43,251
  • 5
  • 22
  • 52
sw dev
  • 11
  • 2
  • Try setting up you -Djava.io.tmpdir to Temp folder and carryout the process. This will make java.io.tmpdir to point to your temp folder. – Sandeep jaju Sep 16 '19 at 05:59
  • How would you know which file to open if you get the right folder? – Joakim Danielson Sep 16 '19 at 06:15
  • The latest file that was opened with the name which i already know what it is. But sometimes if you open the same file multiple times it appends the number to the file name file(1).csv, file(2).csv etc. – sw dev Sep 16 '19 at 06:28
  • Before reader the files, you could list all of the file names in a folder, then find the required files, and read data from it. You could check this articles: [How to read all files in a folder from Java?](https://stackoverflow.com/questions/1844688/how-to-read-all-files-in-a-folder-from-java) and [How to view temporary internet files in Windows 10](https://answers.microsoft.com/en-us/ie/forum/ie11-iewindows_10/how-to-view-temporary-internet-files-in-windows-10/7bd93230-99fa-412b-beaf-c48a46b7c2f9) – Zhi Lv Oct 03 '19 at 07:20
  • Thank you Zhi Lv. That is one way to do it. – sw dev Oct 04 '19 at 11:19

0 Answers0