【问题标题】:how to get the data from file and set to text Area in vaadin如何从文件中获取数据并在vaadin中设置为文本区域
【发布时间】:2017-08-04 18:09:22
【问题描述】:

我已经创建了一个项目。但是我在控制台中获取数据我想将数据设置为 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();
        }

【问题讨论】:

    标签: java eclipse vaadin


    【解决方案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();
        }
    }
    

    【讨论】:

    • 正确答案应标记为答案,@lokeshmenta。
    猜你喜欢
    • 1970-01-01
    • 2015-04-03
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2010-10-04
    • 1970-01-01
    • 2019-11-23
    相关资源
    最近更新 更多