[英]Reading from a .txt file into a JFrame
Just trying to delete this question, sorry. 对不起,我只是想删除这个问题。 It was a stupid question. 这是一个愚蠢的问题。
You could use a BufferedReader
to read each line of the file. 您可以使用BufferedReader
读取文件的每一行。 You could then use String#split
to split the String
on the ~
delimiter and parse the individual elements, for example... 然后,您可以使用String#split
在~
分隔符上拆分String
并解析各个元素,例如...
try (BufferedReader br = new BufferedReader(new FileReader(new File("CarLoan.txt")))) {
String text = null;
System.out.printf("%-20s | %s%n", "Name", "Price");
while ((text = br.readLine()) != null) {
String parts[] = text.split("~");
String name = parts[0];
int price = Integer.parseInt(parts[1]);
System.out.printf("%-20s | %d%n", name, price);
}
} catch (IOException ex) {
ex.printStackTrace();
}
which prints... 打印...
Name | Price
Honda Civic | 10000
Porsche 911 | 50000
Chevrolet Blazer | 20000
Toyota Camry | 15000
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.