?????±???д???????????????Java??????
??????к????Σ?????μ???????????????????????????μ??????????????????????????????
????public static void writeFile1() throws IOException {
????File fout = new File("out.txt");
????FileOutputStream fos = new FileOutputStream(fout);
????BufferedWriter bw = new BufferedWriter(new OutputStreamWriter(fos));
????for (int i = 0; i < 10; i++) {
????bw.write("something");
????bw.newLine();
????}
????bw.close();
????}
?????????????????FileOutputStream???????????FileWriter ??PrintWriter???????????????????????????′???????
???????FileWriter??
????public static void writeFile2() throws IOException {
????FileWriter fw = new FileWriter("out.txt");
????for (int i = 0; i < 10; i++) {
????fw.write("something");
????}
????fw.close();
????}
???????PrintWriter??
????public static void writeFile3() throws IOException {
????PrintWriter pw = new PrintWriter(new FileWriter("out.txt"));
????for (int i = 0; i < 10; i++) {
????pw.write("something");
????}
????pw.close();
????}
???????OutputStreamWriter??
????public static void writeFile4() throws IOException {
????File fout = new File("out.txt");
????FileOutputStream fos = new FileOutputStream(fout);
????OutputStreamWriter osw = new OutputStreamWriter(fos);
????for (int i = 0; i < 10; i++) {
????osw.write("something");
????}
????osw.close();
????}
???????Java?????
????FileWriter is a convenience class for writing character files. The constructors of this class assume that the default character encoding and the default byte-buffer size are acceptable. To specify these values yourself?? construct an OutputStreamWriter on a FileOutputStream.
????FileWriter???д????????????????????????????????????????????????????????????????????????
?????????????????????????????????????OutputStreamWriter??
????PrintWriter prints formatted representations of objects to a text-output stream. This class implements all of the print methods found in PrintStream. It does not contain methods for writing raw bytes?? for which a program should use unencoded byte streams.
????PrintWriter?????????????????????????????????????????????PrintStream?е?????????
????????????????д?????????????????????????δ????????????
???????????????PrintWriter?????Щ?????????????????????println??printf??
???????????????????????I/O????FileWriter?????IOException??PrintWriter??????????IOException????????????????????????????????????????????????checkError()????
????PrintWriter???????????????д??????????????flush ????FileWriter????????????????????flush.