上传本地文件到hdfs
2016-12-19 17:33
288 查看
import org.apache.hadoop.conf.Configuration; import org.apache.hadoop.fs.FileSystem; import org.apache.hadoop.fs.Path; import org.apache.hadoop.io.IOUtils; import org.apache.hadoop.util.Progressable; import java.io.BufferedInputStream; import java.io.FileInputStream; import java.io.InputStream; import java.io.OutputStream; import java.net.URI; /** * Created by CaoSen on 2016-12-19. */ public class TestLocalHdfsjava { public static void main(String[] args)throws Exception{ String localSrc = "C:\\Users\\CaoSen\\Desktop\\tt.scala"; String dst = "hdfs://192.168.42.139:9000/tt.scala"; InputStream in = new BufferedInputStream(new FileInputStream(localSrc)); Configuration conf = new Configuration(); FileSystem fs = FileSystem.get(URI.create(dst), conf); OutputStream out = fs.create(new Path(dst), new Progressable() { public void progress() { System.out.print("."); } }); IOUtils.copyBytes(in, out, 4096, true); out.flush(); out.close(); fs.close(); } }
相关文章推荐
- 向hdfs上传本地文件-Hello World
- 上传本地文件到HDFS
- 上传本地文件到HDFS spark可以直接使用
- java上传本地文件到HDFS简单demo
- 利用java API实现本地文件上传至hdfs
- spark 本地文件上传hdfs
- Hadoop HDFS编程 API入门系列之从本地上传文件到HDFS(一)
- 本地多级文件 原样上传到hdfs
- Hadoop——上传本地文件到hdfs
- hadoop生态系统学习之路(三)java实现上传文件(本地或ftp)至hdfs
- 解决从本地文件系统上传到HDFS时的权限问题
- JAVA实现批量上传本地文件至HDFS
- JAVA实现:将文件从本地上传到HDFS上、从HDFS上读取等操作
- 上传本地文件到HDFS
- 合并本地文件并上传到hdfs
- 把本地文件夹下的所有文件上传到hdfs上并合并成一个文件
- Linux上传本地文件到HDFS
- talend 将本地文件或者mysql文件上传到hadoop/hdfs
- 解决从linux本地文件系统上传文件到HDFS时的权限问题
- 本地多级文件 合并上传到hdfs(递归上传)