java.io 中 Writer 的子类

java.io 中 Writer 的子类
class BufferedWriter
将文本写入字符输出流,缓冲各个字符,从而提供单个字符、数组和字符串的高效写入。
class CharArrayWriter
此类实现一个可用作 Writer 的字符缓冲区。
class FileWriter
用来写入字符文件的便捷类。
class FilterWriter
用于写入已过滤的字符流的抽象类。
从类 java.io.OutputStreamWriter 继承的方法
close, flush, getEncoding, write, write, write
从类 java.io.Writer 继承的方法
append, append, append, write, write
class OutputStreamWriter
OutputStreamWriter 是字符流通向字节流的桥梁:使用指定的 charset 将要向其写入的字符编码为字节。
class PipedWriter
传送的字符输出流。
class PrintWriter
向文本输出流打印对象的格式化表示形式。
class StringWriter
一个字符流,可以用其回收在字符串缓冲区中的输出来构造字符串。

1 import java.io.FileNotFoundException;
2 import java.io.FileOutputStream;
3 import java.io.FileWriter;
4 import java.io.IOException;
5
6
7 public class writeDemo1 {
8
9 /** */ /**
10 * @param args
11 */
12 public static void main(String[] args) {
13 int data[] = {
14 1 , 2 , 3 , 4 , 5 , 6 ,
15 11 , 32 , 423 , 54 , 654 , 123 ,
16 213 , 43 , 53 , 65 , 34 } ;
17
18 try {
19 FileWriter fos = new FileWriter( " FileOutputStream.dat " , true );
20 // true意味着在文件末尾添加,而不是覆原文件
21 // 此处使用FileOutputStream也一样
22 // 但是此处写出来的文件内容似乎不对
23
24 for ( int i = 0 ; i < data.length; i ++ )
25 {
26 fos.write(data);
27 }
28
29 fos.close();
30
31 } catch (FileNotFoundException e) {
32 System.out.println( " Err is + " + e.toString());
33
34 } catch (IOException e) {
35 System.out.println( " Err is + " + e.toString());
36 }
37
38 }
39
40 }
41
42

posted on 2006-08-22 00:39 徐海东 阅读(242) 评论(1) 编辑 收藏 所属分类: J2SE基础学习

# Xu Xiaoxing
public static void main(String[] args) {
int[] data = new int[]{
1,2,3,4,5,6,
11,32, 11,54, 22,123,
44,43,53,65,34 };
try {
File fl = new File("1.txt");
FileOutputStream fos = new FileOutputStream(fl,true);
//true意味着在文件末尾添加,而不是覆原文件
OutputStreamWriter osw = new OutputStreamWriter(fos);
BufferedWriter bfw = new BufferedWriter(osw);
String str = new String(data,0,data.length);
for(int i = 0; i < data.length; i++){
//bfw.write(Integer.toString(data)+",");
//bfw.write(String.valueOf(data)+",");
String s= ""+data;
bfw.write(s);
}
bfw.flush();
bfw.close();
fos.flush();
fos.close();
} catch (FileNotFoundException e) {
System.out.println("Err is + "+e.toString());
} catch (IOException e) {
System.out.println("Err is + "+e.toString());
}
}
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值