Java 如何在vaadin中从文件中获取数据并设置为文本区域
我已经创建了一个项目。但我在控制台中获取数据,我想将数据设置为textareaJava 如何在vaadin中从文件中获取数据并设置为文本区域,java,eclipse,vaadin,Java,Eclipse,Vaadin,我已经创建了一个项目。但我在控制台中获取数据,我想将数据设置为textarea File[] F=File.listFiles(); for (File File1:F) { FileInputStream fstream = null; String strLine ; try { fstream = new FileInputStream(File1); BufferedRea
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();
}
您必须累积读取行,以便以后可以将其添加到文本区域。 您可能会考虑如何处理断线,目前它们只是从最后的字符串/文本中排序出来。
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();
}
}
正确的答案应标记为答案,@Lokeshamenta。