前提是安裝配置好hadoop環境
java
hdfs dfs -put /home/minst_svmlight.txt /home/minst_svmlight.txtoop
本地文件 hdfs上的路徑spa
上傳後的文件名並不必定和原先的同樣。能夠從新命名。
code
public static void fileUp() throws IOException { String target = "hdfs://master:9000/dataanalysis.jar"; String local = "D:/Java/data-analysis.jar"; FileInputStream in = new FileInputStream(new File(local)); Configuration conf = new Configuration(); FileSystem fs = FileSystem.get(URI.create(target), conf); OutputStream out = fs.create(new Path(target)); IOUtils.copyBytes(in, out, 4096, true); log.info("上傳完成。。。。。。。"); }