2013-06-21 55 views
1

我有一个包含几段信息(纯文本)的txt文件,我将如何在textarea中显示此文件。到目前为止,我试过在vaadin布局中显示txt文件

FileResource file = new FileResource(new File("/path/to/file"); 
TextArea text = new TextArea(); 
text.setData(file); 

这不起作用

回答

2

不正确的方法调用

不要使用setData()方法,而是在setValue(....)方法。请参阅Book of VaadinAPI doc中的TextArea主题。

这需要一个字符串,所以您必须从文件中读取字符串中的文本,然后在TextArea上使用setValue()

set/getData()方法允许您保存Vaadin没有使用的“私有”数据。