다음 코드를 사용하여 일부 데이터를 시퀀스 파일 형식 파일에 씁니다. 프로그램이 잠시 실행되면, Eclipse 콘솔의 빨간 버튼을 통해 프로그램을 중단합니다. 그러나 hdfs에서 데이터 파일을 검사 할 때 시퀀스 파일의 크기는 0입니다. 또한 'hadoop fs -text filename'명령을 사용하여 파일을 볼 수 없습니다. SequenceFile.Reader를 사용하여 이전에 작성된 파일을 읽을 때 '스레드의 예외 "주"java.io.EOFException'예외가 발생합니다. 이 경우, 어떻게해야합니까? 내 개발 환경은 CentOS 6에서 eclipse3.7 (Windows 7)과 hadoop 클러스터 (hadoop 버전 1.0.3)입니다.SequenceFile 클래스 쓰기 파일 사용
클래스 순서는 스레드 {
private String uri = "hdfs://172.20.11.60:9000";
private String filePath = "/user/hadoop/input/";
private String fileName = "Sequence-01.seq";
public SequenceFile.Writer writer;
private static int cnt = 0;
private void init() {
Configuration conf = new Configuration();
try {
FileSystem fs = FileSystem.get(URI.create(uri), conf);
writer = SequenceFile.createWriter(fs, conf, new Path(filePath
+ fileName), LongWritable.class, Text.class);
} catch (IOException e) {
// TODO Auto-generated catch block
e.printStackTrace();
}
}
public Sequence() {
init();
}
@Override
public void run(){
while(true){
try {
writer.append(new LongWritable(100), new Text("hello,world"));
cnt++;
if(cnt%100 == 0){
System.out.println("flush current data to file system");
writer.syncFs();
}
} catch (IOException e) {
// TODO Auto-generated catch block
System.out.println("append data error");
e.printStackTrace();
}
try {
Thread.sleep(1000);
} catch (InterruptedException e) {
// TODO Auto-generated catch block
System.out.println("thread interupted");
e.printStackTrace();
}
}
}
}
공용 클래스 TestSequenceFile {
/**
* @param args
*/
public static void main(String[] args) {
// TODO Auto-generated method stub
new Sequence().start();
}
}