How to read file on Windows and Linux from Java

后端 未结 5 1143
攒了一身酷
攒了一身酷 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:09

    If you know the current working directory (test it with:

    System.out.println(new File(".").getAbsolutePath());
    

    you can hardcode a relative directory like ../../XML/RequestXML

    For the record: although this may help, I still believe you should try to solve this with a configuration parameter or by loading it as a resource available in the classpath.

提交回复
热议问题