我创建了一个项目。我在控制台中获取数据我希望将数据设置为textarea
File[] F=File.listFiles();
for (File File1:F) {
FileInputStream fstream = null;
String strLine ;
try {
fstream = new FileInputStream(File1);
BufferedReader br = new BufferedReader(new InputStreamReader(fstream));
while ((strLine = br.readLine()) != null)
System.out.println (strLine);
String str=strLine;
final TextArea txt=new TextArea(str);
layout.addComponents(txt);
//br.close();
} catch (IOException e) {
e.printStackTrace();
}
答案 0 :(得分:1)
您必须累积读取行,以便稍后将其添加到文本区域。 您可能会考虑如何处理换行符,目前它们只是从最终的字符串/文本中排序。
for (File File1:F)
{
FileInputStream fstream = null;
String strLine;
StringBuilder sb= new StringBuilder();
try
{
fstream = new FileInputStream(File1);
BufferedReader br = new BufferedReader(new InputStreamReader(fstream));
while ((strLine = br.readLine()) != null)
{
System.out.println (strLine);
sb.append(str);
}
final TextArea txt=new TextArea(sb.toString());
layout.addComponents(txt);
//br.close();
}
catch (IOException e)
{
e.printStackTrace();
}
}