Tôi đang cố gắng ghi tệp vào HDFS, tệp được tạo nhưng nó là trống trên cụm, tuy nhiên khi tôi chạy mã cục bộ, nó hoạt động như một nét duyên dáng.Đang ghi tệp vào HDFS bằng cách sử dụng Java
đây là mã của tôi:
FSDataOutputStream recOutputWriter = null;
FileSystem fs = null;
try {
//OutputWriter = new FileWriter(outputFileName,true);
Configuration configuration = new Configuration();
fs = FileSystem.get(configuration);
Path testOutFile = new Path(outputFileName);
recOutputWriter = fs.create(testOutFile);
//outputWriter = new FileWriter(outputFileName,true);
} catch (IOException e) {
e.printStackTrace();
}
recOutputWriter.writeBytes("======================================\n");
recOutputWriter.writeBytes("OK\n");
recOutputWriter.writeBytes("======================================\n");
if (recOutputWriter != null) {
recOutputWriter.close();
}
fs.close();
tôi đã bỏ lỡ một cái gì đó?
dữ liệu tuôn ra? https://hadoop.apache.org/docs/r2.6.1/api/org/apache/hadoop/fs/FSDataOutputStream.html#hflush%28%29 – Pierre
@Pierre cảm ơn câu trả lời của bạn, ngay cả khi tôi xóa dữ liệu, tệp vẫn trống! –
Giá trị 'outputFileName' là gì? và bạn đã thử cách giải thích 'fs' và' testOutFile' như thế này (với URI hdfs) http://stackoverflow.com/questions/16000840/write-a-file-in-hdfs-with-java –