题
我正在使用NetBeans首次Java项目。我想使用NetBeans 6.5创建包括约50个文本文件的一个罐子。有没有一种简单的方法来做到这一点?
解决方案
您需要找到您的驱动器上的项目目录。然后把你所有的50个文本文件转换成的src 文件夹中。回到Netbeans的。现在你应该看到你的源代码包下的文本文件。然后点击生成的项目。新创建的JAR应该在你的项目目录的 DIST 文件夹中。
修改强>以下是例如源代码,其从文本文件中的“默认”包的读取。该文件名是 “hello.txt的”。
package testtextfile;
import java.io.InputStream;
import java.util.Scanner;
import javax.swing.JLabel;
import javax.swing.JOptionPane;
public class Main {
public static void main(String[] args) {
InputStream s = Main.class.getClassLoader().getResourceAsStream("hello.txt");
Scanner sc = new Scanner(s);
sc.useDelimiter("\\Z"); // read to the end of file. all at one.
String contents = sc.next();
JOptionPane.showMessageDialog(null, new JLabel(contents));
}
}
其他提示
如果你熟悉蚂蚁,蚂蚁能做到这一点,和Netbeans可以运行Ant脚本。
不隶属于 StackOverflow