|
/** * 上传文件到HDFS上去
*/ private static void uploadToHdfs() throws IOException {
String localSrc = "E:\\test\\article01.txt";
String dst = "/user/test/article04.txt";
FileSystem fs = FileSystem.get(URI.create(HADOOP_URL), conf);
long start = new Date().getTime();
/* InputStream in = new FileInputStream(localSrc);
InputStreamReader isr = new InputStreamReader(in, "GBK");
OutputStream out = fs.create(new Path(HADOOP_URL+dst), true);
IOUtils.copy(isr, out, "UTF8");*/
//该方法更快
FSDataOutputStream outputStream=fs.create(new Path(dst));
String fileContent = FileUtils.readFileToString(new File(localSrc), "GBK");
outputStream.write(fileContent.getBytes());
outputStream.close();
long end = new Date().getTime();
System.out.println("use:"+(end-start));
} |
|
|