파일을 기존 시퀀스 파일에 추가하는 방법에 대한 샘플 코드 스 니펫을 제공해 줄 수 있습니까?// 사용자/{의 homedirectory} : 다음 기존 시퀀스 파일에 추가
내가 기존의 시퀀스 파일 OUTPUTFILE에 추가하는 데 사용되는 코드이지만 시퀀스 파일을 읽는 동안 후에는 체크섬 오류 던지고 추가 :문제 열기 체크섬 파일을 데스크탑/샘플/시퀀스 파일/출력 파일. 무시 예외 : java.io.EOFException
public class AppendSequenceFile {
/**
* @param args
* @throws IOException
* @throws IllegalAccessException
* @throws InstantiationException
*/
public static void main(String[] args) throws IOException,
InstantiationException, IllegalAccessException {
Configuration conf = new Configuration();
FileSystem fs = FileSystem.get(conf);
Path inputFile = new Path("/Users/{homedirectory}/Desktop/Sample/SequenceFile/sampleAppendTextFiles");
Path sequenceFile = new Path("/Users/{homedirectory}/Desktop/Sample/SequenceFile/outputfile");
FSDataInputStream inputStream;
Text key = new Text();
Text value = new Text();
SequenceFile.Writer writer = SequenceFile.createWriter(fs, conf,
sequenceFile, key.getClass(), value.getClass());
FileStatus[] fStatus = fs.listStatus(inputFile);
for (FileStatus fst : fStatus) {
String str = "";
System.out.println("Processing file : " + fst.getPath().getName() + " and the size is : " + fst.getPath().getName().length());
inputStream = fs.open(fst.getPath());
key.set(fst.getPath().getName());
while(inputStream.available()>0) {
str = str+inputStream.readLine();
}
value.set(str);
writer.append(key, value);
}
}
}
시퀀스 파일 리더 : 사전에
public class SequenceFileReader{
public static void main(String[] args) throws Exception {
Configuration conf = new Configuration();
FileSystem fs = FileSystem.get(conf);
Path path = new Path("/Users/{homedirectory}/Desktop/Sample/SequenceFile/outputfile");
SequenceFile.Reader reader = null;
try {
reader = new SequenceFile.Reader(fs, path, conf);
Text key = new Text();
Text value = new Text();
while (reader.next(key, value)) { System.out.println(key);
System.out.println(value);
}
} finally {
IOUtils.closeStream(reader);
}
}
}
감사합니다.
코드 작성자를 요청하는 것 같습니다. 이 솔루션을 찾기 위해 무엇을 스스로 시도 했습니까? –
추가하려고 시도했지만 추가 후 시퀀스 파일을 읽는 동안 체크섬 오류 - – user3400887
체크섬 파일 열 때 문제가 발생했습니다./Users/{homedirectory}/Desktop/Sample/SequenceFile/outputfile. 무시되는 예외 : java.io.EOFException. 그게 내가 여기에 질문을 게시 한 이유 다. 코드로 질문 편집 나는 잠시 동안 노력했다. – user3400887