How to read file on Windows and Linux from Java

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

    Hardcoding file paths is not a recommended practice. You may find a way to build the file path programmatically and use File.separator, which returns the correct one depending on the system ("\" for Windows, and "/" for UNIX/Linux/Macintosh).

提交回复
热议问题