在java中编译文本文件

时间:2016-04-05 18:34:39

标签: java

我正在尝试创建一个带有.txt文件的编译器并使用java编译它。我已经创建了一个,但只编译.java个文件。我使用JavaCompiler类来做到这一点。

其次..获取文件我用过这个:

Class.forName("CLASS_NAME");

如何从项目文件夹中获取外部文件?

1 个答案:

答案 0 :(得分:0)

问:
How to get a file that is external from the project folder?

A:

File aFile = new File("./../../folder1/folder2/test.jpg");
aFile = new File("C:/users/ABC/Desktop/test.png"); //no problems using / in Windows
aFile = new File("/home/ABC/test.pdf");

aFile = new File("D:/Folder");
aFile = new File(aFile, "file2.txt");

只要这些文件夹都不是您的项目文件夹。