Java的RandomAccessFile,FileInputStream,InputStreamReader,BufferedReader,FileOutputStream,OutputStream...

 1 /*
 2  * To change this template, choose Tools | Templates
 3  * and open the template in the editor.
 4  */
 5 package inputtest;
 6 
 7 import java.io.*;
 8 import java.util.Scanner;
 9 import java.util.logging.Level;
10 import java.util.logging.Logger;
11 
12 /**
13  *
14  * @author Lowitty
15  */
16 public class InputTest {
17 
18     static boolean b;
19     /**
20      * @param args the command line arguments
21      */
22     public static void main(String[] args) {
23             /*Scanner in = new Scanner(System.in);
24             
25             String s = in.nextLine();
26             System.out.println("XXX是:" + s);*/
27             
28             //System.out.println(b);
29             
30             
31             //下列是RandomAccessFile类的测试文件
32             /*File file = new File("C:\\Users\\Lowitty\\Desktop\\WuDengJie.txt");
33             try {
34                 file.createNewFile();
35             } catch (IOException ex) {
36                 Logger.getLogger(InputTest.class.getName()).log(Level.SEVERE, null, ex);
37             }
38             try {
39                 RandomAccessFile raf = new RandomAccessFile(file,"rw");
40                 try {
41                     //raf.seek(raf.length());
42                     raf.write("XXX是大美女!!".getBytes());
43                 } catch (IOException ex) {
44                     Logger.getLogger(InputTest.class.getName()).log(Level.SEVERE, null, ex);
45                 }
46             } catch (FileNotFoundException ex) {
47                 Logger.getLogger(InputTest.class.getName()).log(Level.SEVERE, null, ex);
48             }*/
49         
50         FileInputStream fis;
51         InputStreamReader isr;
52         BufferedReader br;
53         
54         FileOutputStream fos;
55         OutputStreamWriter osw;
56         BufferedWriter bw;
57         try {    
58             fis = new FileInputStream("C:\\Users\\Lowitty\\Desktop\\SrcFile.txt");
59             isr = new InputStreamReader(fis);
60             br = new BufferedReader(isr);
61             
62             fos = new FileOutputStream(new File("C:\\Users\\Lowitty\\Desktop\\SrcRes.txt"));
63             osw = new OutputStreamWriter(fos);
64             bw = new BufferedWriter(osw);
65             
66             try {
67                 for(String s = br.readLine(); s != null; s = br.readLine()){
68                     System.out.println(s);
69                     bw.write(s);
70                     bw.flush();
71                     bw.newLine();
72                 }
73             } catch (IOException ex) {
74                 Logger.getLogger(InputTest.class.getName()).log(Level.SEVERE, null, ex);
75             }
76         } catch (FileNotFoundException ex) {
77             Logger.getLogger(InputTest.class.getName()).log(Level.SEVERE, null, ex);
78         }
79         
80         
81         
82     }
83 }

关于RandomAccessFile与大文件的BufferedReader的相关问题及区别。

转载于:https://www.cnblogs.com/lowitty/archive/2012/11/09/2763053.html

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值