posts - 84,  comments - 54,  trackbacks - 0

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[i]);
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 JavaCoffe 阅读(1054) 评论(1)  编辑  收藏 所属分类: J2SE基础学习


FeedBack:
# re: java.io 中 Writer 的子类
2006-08-26 19:59 | 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[i])+",");
//bfw.write(String.valueOf(data[i])+",");
String s= ""+data[i];
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());
}

}
  回复  更多评论
  

只有注册用户登录后才能发表评论。


网站导航:
 
<2006年8月>
303112345
6789101112
13141516171819
20212223242526
272829303112
3456789

常用链接

留言簿(5)

随笔分类(80)

收藏夹(1)

最新随笔

积分与排名

  • 积分 - 56727
  • 排名 - 900

最新评论

阅读排行榜