【发布时间】:2020-07-27 22:05:57
【问题描述】:
我创建了一个名为 SampleView 的 Eclipse PDE 视图。目前,为了以编程方式在视图上显示我的文件的输出,我正在使用文件中的每一行,并使用扫描仪打印到视图。 这是显示文件数据的最佳方式吗?或者是否有更好的现有函数可以在我的代码中使用以在视图中打开文件?
SampleView 的代码:
public class SampleView extends ViewPart {
/**
* The ID of the view as specified by the extension.
*/
public static final String ID = "asher.views.id.SampleView";
@Inject IWorkbench workbench;
@Override
public void createPartControl(Composite parent) {
Text text = new Text(parent, SWT.READ_ONLY | SWT.V_SCROLL | SWT.H_SCROLL);
File file = new File("/Users/user/Desktop/untitled.json");
Scanner sc;
try {
sc = new Scanner(file);
while (sc.hasNextLine())
text.setText(text.getText()+"\n"+sc.nextLine());
sc.close();
} catch (FileNotFoundException e) {
// TODO Auto-generated catch block
e.printStackTrace();
}
}
@Override
public void setFocus() {
}
}
【问题讨论】:
标签: java eclipse eclipse-plugin pde