import java.io.BufferedReader; import java.io.File; import java.io.FileReader; import java.io.IOException;
public String fileContext(String path) { String context = ""; File file = new File(path); if (file.exists()) { try (BufferedReader reader = new BufferedReader(new FileReader(path))) { String line; while ((line = reader.readLine()) != null) { context = context + "\n" + line; } } catch (IOException e) { e.printStackTrace(); } }else{ context="该文件不存在"; } return context; }