SSISO Community

시소당

자바 !! io,한줄받기,파일읽고쓰기,FileReader,FileWriter

!!  io,한줄받기,파일읽고쓰기,FileReader,FileWriter
=======================================
한줄받기

import  java.io.*;
class  Test1{
  public  static  void  main(String[]  args){
    byte[]  bt  =  new  byte[128];
    /*
    try{
      System.in.read(bt);
      System.out.print(new  String(bt));
    }catch(Exception  e){}
    */

    
    int  i  =  0,c  =  0;
    try{
      while((c=System.in.read())!=(-1)){
        if(c!=13  &&  c!=10){
          bt[i++]=(byte)c;
        }else{
          System.out.print(new  String(bt));
          i=0;
          bt=  new  byte[128];
        }

      }
    }catch(Exception  e){}    

  }
}
==================================================
import  java.io.*;

class  TestFileWriter
{
  public  static  void  main(String[]  args){
    int  c=0;
    int  idx=0;
    try{
      FileWriter  fw=new  FileWriter("a.txt");
      byte[]  buf=new  byte[32];
      while((c=System.in.read())!=-1){
        if(c!=13&&c!=10){
          buf[idx++]=(byte)c;
        }else{
          System.out.println(new  String(buf,0,idx));
          fw.write(new  String(buf,0,idx));
          fw.close();
//          idx=0;
//          buf=new  byte[32];
          java.util.Arrays.fill(buf,(byte)0);//초기화
        }
      }
    }catch(Exception  e){}


  }
}
====================================================
import  java.io.*;

class    FileReaderTest
{
  public  static  void  main(String[]  args)
  {
    byte[]  bt  =  new  byte[50];
    try{
    FileReader  fr  =  new  FileReader("a.txt");
    int  n  =  0  ;
    while((n  =  fr.read())!=-1){
      System.out.print((char)n);
    }
    }
    catch(Exception  e){}
  }
}

출처  3/29(목)  자바  !!  io,한줄받기,파일읽고쓰기,FileReader,FileWriter|작성자  네이아
http://blog.naver.com/akswnsjd1?Redirect=Log&logNo=60035696037

1282 view

4.0 stars