如果没有读取错误,我将无法读取以.docx结尾的文件。 我需要有关javaFx组件上显示的语言的帮助。
public void Button1Action(ActionEvent event) throws IOException {
File file = null;
FileChooser fileChooser = new FileChooser();
fileChooser.setInitialDirectory(new File ("C:\\Users\\Admin\\Desktop\\Software Engineering\\Final Courses\\Final Project\\Projects on Eclipse\\Project Lab"));
fileChooser.getExtensionFilters().addAll(
new ExtensionFilter("DOCX Files", "*.docx"));
//FileInputStream fileChooser = new FileInputStream(fileChooser.getAbsolutePath());
fileChooser.setTitle("Open Resource File");
File selectedFile = fileChooser.showOpenDialog(null);
StringBuffer contents = new StringBuffer();
FileReader reader = null;
//BufferedReader reader = null;
new InputStreamReader(new FileInputStream(selectedFile), StandardCharsets.UTF_8);
Scanner in = new Scanner(new FileReader(selectedFile));
String content;
reader = new FileReader(selectedFile);
char[] chars = new char[(int) selectedFile.length()];
reader.read(chars);
content = new String(chars);
reader.close();
if(selectedFile != null) {
textFile.getItems().add(content);
} else {
System.out.println("file is not valid");
}
}