java关于路径的代码
import java.io.File;
import java.io.IOException;
public class HelloWorld {
public static void main(String[] args) throws IOException {
System.out.println(System.getProperty("user.dir"));//这是得到工程的路径
String path="E:\\myjavacode\\Server_study01\\src\\cn\\jd\\server\\basic\\p.xml";
File src=new File(path);
System.out.println(src.getAbsolutePath());//获得绝对路径
// System.out.println(src.getCanonicalPath());
String filePath = "src/1.txt";
File file = new File(filePath);
System.out.println(file.exists());
try {
file.createNewFile();
} catch (IOException e) {
e.printStackTrace();
}
System.out.println(file.exists());
}
}

