Java?????????FileManager
???????????? ???????[ 2014/3/11 9:32:05 ] ????????Java ????
??????д??????????????????ν???????????θ???????????鷳???????????????????????????д??????????????????????????????????????????÷???????
import java.io.BufferedReader;
import java.io.FileInputStream;
import java.io.FileOutputStream;
import java.io.InputStreamReader;
import java.io.OutputStreamWriter;
import java.util.ArrayList;
import java.util.List;
public class FileManager {
public static String read(String fileName?? String encoding) {
StringBuffer fileContent = new StringBuffer();
try {
FileInputStream fis = new FileInputStream(fileName);
InputStreamReader isr = new InputStreamReader(fis?? encoding);
BufferedReader br = new BufferedReader(isr);
String line = null;
while ((line = br.readLine()) != null) {
fileContent.append(line);
fileContent.append(System.getProperty("line.separator"));
}
br.close();
isr.close();
fis.close();
} catch (Exception e) {
e.printStackTrace();
}
return fileContent.toString();
}
public static void write(String fileContent?? String fileName?? String encoding) {
try {
FileOutputStream fos = new FileOutputStream(fileName);
OutputStreamWriter osw = new OutputStreamWriter(fos?? encoding);
osw.write(fileContent);
osw.flush();
osw.close();
fos.close();
} catch (Exception e) {
e.printStackTrace();
}
}
}
?????????????
????д?? FileManager.write("Hello?? World!"?? "D:\test.txt"?? "UTF-8");
??????? System.out.println(FileManager.read("D:\test.txt"?? "UTF-8"));
??????
???·???
??????????????????
2023/3/23 14:23:39???д?ò??????????
2023/3/22 16:17:39????????????????????Щ??
2022/6/14 16:14:27??????????????????????????
2021/10/18 15:37:44???????????????
2021/9/17 15:19:29???·???????·
2021/9/14 15:42:25?????????????
2021/5/28 17:25:47??????APP??????????
2021/5/8 17:01:11