hdfs的java接口简单示例
2024-08-24 07:50:30
public class HDFSDemo { private FileSystem fs = null;
@Before
public void init() throws IOException, URISyntaxException, InterruptedException{
fs = FileSystem.get(new URI("hdfs://localhost:9000"), new Configuration());
}
@Test
//递归删除文件或者文件夹
public void testDel() throws IllegalArgumentException, IOException{
boolean flag = fs.delete(new Path("/test"),true);
System.out.println(flag);
}
@Test
//创建目录
public void testMkdir() throws IllegalArgumentException, IOException{
boolean flag = fs.mkdirs(new Path("/Google3Papers"));
System.out.println(flag);
}
@Test
//上传文件
public void testUpload() throws IllegalArgumentException, IOException{
FSDataOutputStream out = fs.create(new Path("/Google3Papers/Google-Bigtable1.0.pdf"));
FileInputStream in = new FileInputStream(new File("/Users/fengmingyue/Desktop/Google-Bigtable1.0.pdf"));
IOUtils.copyBytes(in, out, 2048, true);
}
@Test
//下载文件
public void testDownload() throws IllegalArgumentException, IOException{
InputStream in = fs.open(new Path("/test"));
FileOutputStream out = new FileOutputStream(new File("/Users/fengmingyue/Desktop/ttt"));
IOUtils.copyBytes(in, out, 2048, true);
}
}
最新文章
- 修改远程桌面连接端口3389,RDP-Tcp的portnumber要用十六进制修改
- SQLSERVER如何查看索引缺失
- TeamTalk源码分析之login_server
- js实现拖拽
- Configure SSL for SharePoint 2013
- 基于网页内容数据采集 PHP开发学习笔记
- 线程入门之实现Runnable接口和继承Thread类
- [Cocos2d-x for WP8学习笔记] HelloWorld结构分析
- ACM - ICPC World Finals 2013 B Hey, Better Bettor
- PythonCrawl自学日志(3)
- C语言中如何使用宏
- nginx源代码分析--高性能server开发 常见的流程模型
- Java 内存架构
- Nicholas C. Zakas谈怎样才能成为优秀的前端工程师
- 安卓图表引擎AChartEngine(四) - 源码示例 嵌入Acitivity中的折线图
- IntelliJ IDEA 创建 Maven简单项目
- vue单文件组件实例1:简单单文件组件
- [Java] 方法 -- 繼承關係
- 嵌入式linux教程
- goto语句引起的crosses initialization of XXX
热门文章
- 【代码笔记】iOS-cell自动变化大小
- 【java错误】System.out.println()出错
- cocos2d-x学习网站
- 一步一步 Pwn RouterOS之exploit构造
- 跨域调用报表展现页面的flash打印方法
- linux rpm命令之查询包安装与否、包详细信息、包安装位置、文件属于哪个包、包依赖
- linux 目录操作命令 mkdir、rmdir、cd -、cp、scp、mv、rm
- lsnrctl 与 tnsnames.ora 的联系
- Centos 使用C++11 编译
- 风险管理,未雨绸缪——《代码之殇》读书笔记II