简体   繁体   English

src目录中文件的路径

[英]Path to file in src directory

I am using a method that requires a string path to a file that is in my src directory structure in eclipse. 我正在使用一种方法,该方法需要Eclipse的src目录结构中文件的字符串路径。 Is the path to this file simply src\\fileName.txt or is there a different way i should be getting this file as it doesnt seem to be working currently 这个文件的路径是简单的src \\ fileName.txt还是有其他方式我应该获取这个文件,因为它目前似乎无法正常工作

Thanks 谢谢

Run this and you will never forget how to remember. 运行此命令,您将永远不会忘记如何记住。

File file = new File("sample.txt"); File file = new File(“ sample.txt”); System.out.println(file.getAbsolutePath()); System.out.println(file.getAbsolutePath());

If you are following the maven standard directory structure, class files will be located relative to the classpath like so: 如果您遵循Maven标准目录结构,则类文件将相对于类路径定位,如下所示:

If you want SomeClass.class , you would access it by com.mydomain.packageorappname.deeperpackage.SomeClass . 如果需要SomeClass.class ,则可以通过com.mydomain.packageorappname.deeperpackage.SomeClass访问它。 Is that what you are asking? 那是你的要求吗?

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM