【发布时间】:2016-06-22 19:44:00
【问题描述】:
我有一个带有记事本式功能的程序。当我打开它时,我希望从文本文件中保存的文本自动加载到文本区域。
我有两节课。 Writer 类(应该出现保存的文本)和 Load 类,它实际上从文本文件中导入文本。
作家类:
public class Writer extends Application {
private FlowPane notepadLayout = new FlowPane(Orientation.VERTICAL);
private Scene notepadScene = new Scene(notepadLayout,600,300);
private TextArea inputArea = new TextArea();
private void notepadSetup(){
Text titleText = new Text("Notepad");
notepadLayout.getChildren().add(titleText);
notepadLayout.getChildren().add(inputArea);
}
public void start(Stage primaryStage) throws Exception {
notepadSetup();
Load.loadOperation();
primaryStage.setTitle("ROBOT V1!");
primaryStage.setScene(notepadScene);
primaryStage.show();
所以上面的类有文本区域。我想要做的是使用下面的类将文本文件中的信息加载到上面的文本区域中。
public class Load {
private static String line;
static ArrayList<String> x = new ArrayList<>();
public static void loadOperation(){
try{
BufferedReader br = new BufferedReader (new FileReader("Notes.txt"));
line = br.readLine();
while(line != null){
x.add(line);
line = br.readLine();
}
}catch(Exception e){
}
System.out.println(x);
}
Load.loadOperation 行打印出文本文件中的内容。如何让它加载到文本区域?它还必须保存格式(换行符)。
【问题讨论】:
-
您的代码甚至无法编译。
-
@James_D 现在可以了
标签: java javafx textarea bufferedreader