'BufferedReader'에 해당되는 글 1건

  1. 2008.05.09 [java] BufferedReader..

[java] BufferedReader..

Java 2008.05.09 15:23

String word_list_dir = "d:/java/text.txt";
File dataDir = new File(word_list_dir);

if(dataDir.isHidden() || !dataDir.exists() || !dataDir.canRead()) {
   return;
  }

try {
   BufferedReader in = new BufferedReader( new FileReader ( dataDir ));
   while( (buffer = in.readLine()) != null ) {

    //row 단위 문장을 처리합니다.

   }
  }catch(Exception e){

  }



................................

import java.io.*;


public class TextFileCopy
{
    public static void main( String[] args ) throws IOException
    {
        File inputFile = new File( "D:/Java/Exercise/sourceText.txt" );
        File outputFile = new File( "targetText.txt" );
        BufferedReader fileInput = new BufferedReader( new FileReader( inputFile ) );
        BufferedWriter fileOutput = new BufferedWriter( new FileWriter( outputFile ) );
        String temp = null;
               
        while( ( temp = fileInput.readLine() ) != null )
        {
            fileOutput.write( temp + "\n" );
        }
       
        fileInput.close();
        fileOutput.close();
    }
}


!!FileInputStream,FileOutputStream,InputStreamReader,bufferedWriter,bufferedReader,URL
======================================
복사

import java.io.*;

class  FileCopyTest
{
 public static void main(String[] args)
 {
  try{
  FileInputStream fis = new FileInputStream ("sing.jpg") ;
  FileOutputStream fos = new FileOutputStream ("sing1.jpg");
  int n = 0;
  while ((n=fis.read())!=-1)
  {
   fos.write(n);
  }
  fos.close();
  fis.close();
 
  }catch(Exception e){}
 }
}
==================================================
다른 복사

import java.io.*;

class  FileCopyTest1
{
 public static void main(String[] args)
 {
  try{
  byte[] bt = new byte[1024];

  FileInputStream fis = new FileInputStream ("sing.jpg") ;
  FileOutputStream fos = new FileOutputStream ("sing21.jpg");
 
 
  int i;
  while((i=fis.read(bt))!=-1) fos.write (bt,0,i);
  fos.close();
  fis.close();
 
  }catch(Exception e){}
 }
}
==================================================
txt파일을 화면에 출력

import java.io.*;
class  InputStreamReaderTest
{
 public static void main(String[] args)
 {
  try{
  InputStreamReader isr = new InputStreamReader(new FileInputStream("InputStreamReaderTest.java"));
  int i=0;
  while((i=isr.read ())!=-1){
   System.out.print((char)i);
  }

  }catch(Exception e){}

 }
}
============================================
BufferedReader를 이용하고 bufferedWriter를사용하여 파일복사

import java.io.*;
class  BufferedReaderTest
{
 public static void main(String[] args)
 {
  try{
   int i;
   BufferedReader br = new BufferedReader( new InputStreamReader(new FileInputStream("InputStreamReaderTest.java")));
   BufferedWriter bw = new BufferedWriter (new OutputStreamWriter(new FileOutputStream("a1.java")));
   
   String line = null;

   while((line=br.readLine())!=null){
    bw.write (line,0,line.length());
    bw.newLine();
   }
   bw.close();
   br.close();

  }catch(Exception e){}

 }
}


출처 : 주넝아???? | 네이아
원문 : http://blog.naver.com/akswnsjd1/60035968311

Posted by 용식