import org.apache.flink.core.fs.FileSystem; //导入方法依赖的package包/类

/**

* Test that {@link FileUtils#deletePathIfEmpty(FileSystem, Path)} deletes the path if it is

* empty. A path can only be empty if it is a directory which does not contain any

* files/directories.

*/

@Test

public void testDeletePathIfEmpty() throws IOException {

final Path basePath = new Path(hdfsURI);

final Path directory = new Path(basePath, UUID.randomUUID().toString());

final Path directoryFile = new Path(directory, UUID.randomUUID().toString());

final Path singleFile = new Path(basePath, UUID.randomUUID().toString());

FileSystem fs = basePath.getFileSystem();

fs.mkdirs(directory);

byte[] data = "HDFSTest#testDeletePathIfEmpty".getBytes(ConfigConstants.DEFAULT_CHARSET);

for (Path file: Arrays.asList(singleFile, directoryFile)) {

org.apache.flink.core.fs.FSDataOutputStream outputStream = fs.create(file, FileSystem.WriteMode.OVERWRITE);

outputStream.write(data);

outputStream.close();

}

// verify that the files have been created

assertTrue(fs.exists(singleFile));

assertTrue(fs.exists(directoryFile));

// delete the single file

assertFalse(FileUtils.deletePathIfEmpty(fs, singleFile));

assertTrue(fs.exists(singleFile));

// try to delete the non-empty directory

assertFalse(FileUtils.deletePathIfEmpty(fs, directory));

assertTrue(fs.exists(directory));

// delete the file contained in the directory

assertTrue(fs.delete(directoryFile, false));

// now the deletion should work

assertTrue(FileUtils.deletePathIfEmpty(fs, directory));

assertFalse(fs.exists(directory));

}

java mkdirs 示例_Java FileSystem.mkdirs方法代码示例相关推荐

  1. java secretkey用法_Java SecretKeyFactory.generateSecret方法代码示例

    本文整理汇总了Java中javax.crypto.SecretKeyFactory.generateSecret方法的典型用法代码示例.如果您正苦于以下问题:Java SecretKeyFactory ...

  2. java polygon 用法_Java Polygon.getBounds方法代码示例

    import java.awt.Polygon; //导入方法依赖的package包/类 private SelectionShape translatePointsToRealSize(Select ...

  3. java makedir用法_Java Files.makeDir方法代码示例

    import org.nutz.lang.Files; //导入方法依赖的package包/类 protected void download(String openid, String media_ ...

  4. java args包_Java Args.positive方法代码示例

    import org.apache.http.util.Args; //导入方法依赖的package包/类 /** * Creates new instance of BHttpConnectionB ...

  5. java shape用法_Java PShape.scale方法代码示例

    import processing.core.PShape; //导入方法依赖的package包/类 public void updateAnim(){ if(pg_src_small == null ...

  6. java round指令_Java PApplet.round方法代码示例

    import processing.core.PApplet; //导入方法依赖的package包/类 public static final void updatePos() { if(follow ...

  7. java gettext用法_Java Context.getText方法代码示例

    import android.content.Context; //导入方法依赖的package包/类 /** * Song Details * * @param context * @param t ...

  8. java soap封装_Java SOAPMessage.writeTo方法代码示例

    import javax.xml.soap.SOAPMessage; //导入方法依赖的package包/类 private byte[] createProbeXML() throws SOAPEx ...

  9. java note项目_Java Request.setNote方法代码示例

    import org.apache.catalina.connector.Request; //导入方法依赖的package包/类 /** * Perform single-sign-on suppo ...

  10. java listview用法_Java ListView.setMultiChoiceModeListener方法代码示例

    import android.widget.ListView; //导入方法依赖的package包/类 @Override public void onActivityCreated(@Nullabl ...

最新文章

  1. Eclipse 下新建MAVEN项目
  2. 如何使用PyTorch的量化功能?
  3. 数据库原理与应用(SQL Server)笔记 第三章 连接查询
  4. 想尽快进入游戏开发行业的必经之路!
  5. 【转】!!c#文件系统操作类继承关系图
  6. LeetCode 383. Ransom Note
  7. 微服务和分布式的区别_大话中台三:中台的搭建,分布式与微服务
  8. 7-4 谁会留下?规则如下:所有的学生绕成一圈,顺序排号,从第一个学生开始报数,凡是报到固定数字(例如 5)的都退出,直到只剩下一位学生游戏才中止。 (10 分)
  9. 单元测试用例设计原则
  10. 怎么用计算机解锁,一加6T解锁BL教程,利用电脑进行一键解锁Bootloader操作
  11. c#语法糖模式匹配【switch 表达式】
  12. 计算器模拟器中的情怀——Free42简介
  13. HDMI 2.1的traning流程
  14. 从1亿美元到10亿美元,博世/大陆看到的自动驾驶量产技术趋势
  15. HIve 中 collect_list和collect_set 函数的使用总结
  16. CS中如何去处鼠标加速度及鼠标的相关设置
  17. c语言括号表示法画树怎么画,树的画法分类讲解
  18. iphone刷机各种错误
  19. 常用的Docker镜像
  20. ANSYS Workbench接触设置面板各参数含义详解

热门文章

  1. 永磁同步电机的矢量控制策略(十五)一一一Ansys Simplorer和Matlab/Simulink联合仿真
  2. 插入iPhone,iPad或存储卡后如何阻止iPhoto启动
  3. 详解缺页中断-----缺页中断处理(内核、用户)
  4. 「读书」你当像鸟飞往你的山
  5. 活剥MS06-014网马变种纪实
  6. iOS /OC之视频、音频、相机、相册综合
  7. sql server日期比较
  8. 算法--冒泡排序原理
  9. 智能运维,为新型数据中心注入科技动能
  10. Redis主从复制与Redis集群