从 .txt 逐行读取填充 JList
我想从 .txt 填充 JList 我无法填充 JList... 代码如下:
.txt 的格式如下示例:
name1
name2
name3
JList 的声明方式如下:
private javax.swing.JList jList1
这是用于逐行读取的方法:
private void visualizzaRosa(java.awt.event.ActionEvent evt) {
// TODO add your handling code here:
fileSquadra = squadra.getText();
try {
FileInputStream fstream = new FileInputStream("C:/Users/Franky/Documents....");
DataInputStream in = new DataInputStream(fstream);
BufferedReader br = new BufferedReader(new InputStreamReader(in));
String strLine;
while ((strLine = br.readLine()) != null) {
Jlist1.add(strline); //to populate jlist
System.out.println(strLine); //to print on consolle
}
in.close();
} catch (Exception e) {
}
}
谢谢
I want to populate a JList from a .txt
I can't populate the JList...
Here's the code:
The .txt is formatted like this sample:
name1
name2
name3
The JList is declared in this way:
private javax.swing.JList jList1
This is the method used to read line by line:
private void visualizzaRosa(java.awt.event.ActionEvent evt) {
// TODO add your handling code here:
fileSquadra = squadra.getText();
try {
FileInputStream fstream = new FileInputStream("C:/Users/Franky/Documents....");
DataInputStream in = new DataInputStream(fstream);
BufferedReader br = new BufferedReader(new InputStreamReader(in));
String strLine;
while ((strLine = br.readLine()) != null) {
Jlist1.add(strline); //to populate jlist
System.out.println(strLine); //to print on consolle
}
in.close();
} catch (Exception e) {
}
}
Thanks
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(2)
尝试
Try
然后使用 API 中的 read() 方法。无需编写自定义代码:
Then use the read() method that is part of the API. THere is no need to write custom code: