StringBuilder result = new StringBuilder("");
ClassLoader classLoader = getClass().getClassLoader();
File file = new File(classLoader.getResource("DBase.dat").getFile());
try (Scanner scanner = new Scanner(file)) {
while (scanner.hasNextLine()) {
String line = scanner.nextLine();
result.append(line).append("\n");
}
jTextArea1.setText(result.toString());
scanner.close();
} catch (FileNotFoundException ex) {
}
I am new to JAVA and netBeans I am using this code to read a text file from resources folder and then populate jTextArea from that file. But I am getting Errors. I want to read textfile line by line not all the text at once... Please Help me what should I do. I am pasting a picture too... Project Picture
尝试这样的事情:
File file = new File(classLoader.getResource("DBase.dat").getPath());
The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.