1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31
|
import java.io.*;
public class File{ private String path; public File(String path) { this.path = path; } public String readToString() throws IOException { FileInputStream input = new FileInputStream(path); InputStreamReader reader = new InputStreamReader(input,"UTF-8"); BufferedReader bufferedReader = new BufferedReader(reader); String context = ""; String line = null; while ((line = bufferedReader.readLine()) != null) { context += line + "n"; } bufferedReader.close(); reader.close(); input.close(); return context; } public void writeString(String content) throws IOException{ FileOutputStream output = new FileOutputStream(path); OutputStreamWriter writer = new OutputStreamWriter(output,"UTF-8"); PrintWriter printer = new PrintWriter(writer); printer.print(content); printer.close(); writer.close(); output.close(); } }
|
近期评论