java - 如何从文件中获取数据并将其设置到vaadin中的文本区域

标签 java eclipse vaadin

我已经创建了一个项目。但是我在控制台中获取数据,我想将数据设置到文本区域

    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();
    }
}

关于java - 如何从文件中获取数据并将其设置到vaadin中的文本区域,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/42785442/

相关文章:

java - Vaadin - Tomcat 上的可序列化错误

java - 如何将 spring mail session jndi xml 配置迁移到 java config

java - Spring MVC : Error 400 The request sent by the client was syntactically incorrect

java - 如何在 eclipse kepler 中动态重新加载 GUI?

eclipse - IPython 在 PyDev 控制台中不可用

java - 按下 Enter 键时会触发 Vaadin ComboBox 模糊事件

java - 一次删除多封电子邮件

java - 集合排序不适用于自定义 ArrayList

java - (Eclipse) useBean 类属性的值无效

java - Spring - I18n - 通过静态类访问 MessageSource?