java file path processing windows and linux compatibility

  window and linux separator is actually \ differences and /, in fact, make the file path according to different systems and different servers on it, but java has provided us with a method  System.getProperty ( "file.separator") energy system based on acquiring different file path separator. Try to use when stitching File.separator file path, the path is not compatible with the platform to avoid errors caused . Use example:

File myFile = new File("C:" + File.separator + "tmp" + File.separator, "test.txt");

 

Guess you like

Origin www.cnblogs.com/liuenyuan1996/p/11101930.html