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的相关问题及区别。