hdfs java操作
来源:互联网 发布:ubuntu 安装 sublime 编辑:程序博客网 时间:2024/05/22 14:50
hdfs java操作
一般操作都是shell命令,记一下java操作
package hdfs;import java.io.FileInputStream;import java.net.URI;import org.apache.hadoop.conf.Configuration;import org.apache.hadoop.fs.FSDataOutputStream;import org.apache.hadoop.fs.FileSystem;import org.apache.hadoop.fs.Path;import org.apache.hadoop.fs.Trash;import org.apache.hadoop.io.IOUtils;public class HDFS{public static void main(String[] args) throws Exception {//http://www.baidu.comfinal FileSystem fileSystem = FileSystem.get(new URI("hdfs://server4:9000"), new Configuration());System.out.println("**************"+fileSystem.toString());System.out.println("**************"+fileSystem.getClass());//创建文件夹mkdirs//fileSystem.mkdirs(new Path("mydir"));//fileSystem.mkdirs(new Path("/dir2"), new FsPermission("111"));//上传文件create//final FSDataOutputStream out = fileSystem.create(new Path("/dir1/file1"), true, 1024000, (short)2, 1048576);//final FileInputStream in = new FileInputStream("/root/Downloads/hello");//IOUtils.copyBytes(in, out, 1024, true);//final AtomicInteger writeBytes = new AtomicInteger(0);//final FSDataOutputStream out = fileSystem.create(new Path("/dir1/file2"), new Progressable() {//@Override//public void progress() {//System.out.println("WriteBytes = "+writeBytes.get());//}//});////final FileInputStream in = new FileInputStream("/root/Downloads/hello");//byte[] buffer = new byte[4];//int readBytes = in.read(buffer);//while(readBytes!=-1) {//out.write(buffer);//out.flush();//out.hsync();//writeBytes.addAndGet(readBytes);//readBytes = in.read(buffer);//}//读取数据//final FSDataInputStream in = fileSystem.open(new Path("/dir1/file1"));//IOUtils.copyBytes(in, System.out, 1024, true);//遍历//final FileStatus[] listStatus = fileSystem.listStatus(new Path("/"));//for (FileStatus fileStatus : listStatus) {//System.out.println(fileStatus);//}//获取工作目录//fileSystem.getWorkingDirectory().toString();//删除final Trash trash = new Trash(fileSystem, fileSystem.getConf());trash.moveToTrash(new Path("/dir1/file1"));fileSystem.delete(new Path("/dir1/file1"), true);}}
1 0
- HDFS java 操作 HDFS
- java操作HDFS文件系统
- 使用java操作HDFS
- Java API操作HDFS
- java对hdfs操作
- HDFS 的 JAVA操作
- java操作hdfs
- 使用java操作hdfs
- hadoop java操作hdfs
- java操作hdfs
- java操作hdfs
- Java 访问 HDFS操作
- HDFS-JAVA操作
- Java API操作HDFS
- Java操作HDFS对象
- hdfs java操作
- java操作hdfs
- JAVA操作HDFS案例
- opencv学习笔记(四)高斯滤波
- parent-child 关系介绍
- 杭电2548两军交锋
- Scikit-learn实战之最近邻算法
- springMVC版本和jdk版本不匹配造成的问题
- hdfs java操作
- SE复习日记【三】Life is short, you need Python
- Dev-C++ “to_string is not a member of std” error- 已解决
- 使用 getopt() 、getopt_long()、getopt_long_only()进行命令行处理
- React-Native填坑之TextInput value属性
- SlidingMenu
- 获取2~100的质数
- mysql_real_query()使用说明!
- g2o std::bad_typeid EdgeSE3PointXYZ