이렇게 해 보세요..


[ Follow Ups ] [ Post Followup ] [ 자바 묻고 답하기 ]

Posted by 최대류 on November 25, 1997 at 16:47:55:

In Reply to: RandomAccessFile을 이용해 text형태의 자료를 읽고 출력하기.. posted by 김영래 on November 25, 1997 at 14:13:50:


RandomAccessFile 을 이용해서 하시려면요 다음과 같이 하시면 되구요..
arg[0]값을 읽을 화일 이름으로 갖습니다.


import java.io.*;
public class fileread {
public static void main(String args[]){
try {
RandomAccessFile file = new RandomAccessFile(args[0], "rw");
while(file.getFilePointer() < file.length()){
System.out.println(file.readLine());
}
file.close();
} catch(Exception e) { System.out.println("Error : " + e);
}
}
}


JDC(Java Developers Connection)에서 추천해주는 빠른 file 입출력은 다음과 같습니다.
참고로 요건 제가 조금 고쳤습니다. 원래거는 file간의 복사를 해주는 프로그램이거든요..
마찬가지로 arg[0]값이 읽을 화일 이름입니다.


import java.io.*;


public class readwrite {
public static void main(String args[])
{


String in_file = args[0];


try {
BufferedReader buf_reader =
new BufferedReader(new FileReader(args[0]));
String ln = null;
while ((ln = buf_reader.readLine()) != null){


System.out.println(ln);
}
buf_reader.close();
}
catch (IOException e) {
System.err.println(e);
System.exit(1);
}
}
}




Follow Ups:



이어서 글올리기(답하기)

이름:
E-Mail:
제목:
내용:
관련 URL(선택):
URL 제목(선택):
관련 이미지 URL:


[ Follow Ups ] [ Post Followup ] [ 자바 묻고 답하기 ]