How to read file on Windows and Linux from Java

后端 未结 5 1182
攒了一身酷
攒了一身酷 2021-01-17 06:53

I have a xml file located in D:\\XML\\RequestXML and I am reading xml file in this folder from a FileReader. In my program I hard coded the file pa

5条回答
  •  既然无缘
    2021-01-17 07:13

    The issue isn't easy to solve because of the fundamental differences in the file systems. (Edit: Ignore me, I'm clearly on Cough Medicine. As Djon pointed out below).

    Windows\Uses\Folder\Structures\Like\This.txt

    Linux/Uses/Folder/Structures/Like/This.txt

    So, the only way to handle this accordingly is to detect the operating system it runs on first, and then build your file paths accordingly.

    See this question for more details:

    How do I programmatically determine operating system in Java?

提交回复
热议问题