我在我的eclipse项目Proj中创建了一个新文件夹Fold。如何获得相对于Proj的折叠路径?此文件夹将用作存储序列化对象的位置。我能用这个相对路径序列化和反序列化我的代码吗?
答案 0 :(得分:0)
ClassLoader classLoader = Thread.currentThread().getContextClassLoader();
URL url = classLoader.getResource("path/folder");
或
URL url = getClass().getResource("path/folder");
答案 1 :(得分:0)
此代码获取路径 -
String absolutePath = new File(".").getAbsolutePath();
System.out.println(absolutePath);// Shows you the path of your Project Folder
int last = absolutePath.length()-1;
absolutePath = absolutePath.substring(0, last);//Remove the dot at the end of path
System.out.println(absolutePath);
String filePath = "MyFolderInsideEclipseProject\\file.txt";//You know this
System.out.println(absolutePath + filePath);//Get the full path.