Apache Common-IO 使用
Apache Common-IO 是什么?
Apache File 工具类,能够方便的操作 File
运行环境
jdk 1.7
commons-io 2.6
测试代码
package com.m.basic; import org.apache.commons.io.FileUtils;
import org.junit.Test; import java.io.File;
import java.io.IOException;
import java.net.URL; public class FileUtilTest { String path = "D:/malin/xxx/file.txt"; @Test
public void makeFileTest() throws IOException {
final File file = new File("D:/malin/sss/");
FileUtils.forceMkdir(file);
} @Test
public void forceMkdirParentTest() throws IOException {
File file = new File(path);
FileUtils.forceMkdirParent(file);
if (!file.createNewFile()) {
String message = "Unable to create File " + path;
throw new IOException(message);
} else {
System.out.println("create success");
}
} @Test
public void writingFileTest() throws IOException {
File file = new File(path);
for (int i = 0; i < 3; i++)
FileUtils.writeStringToFile(file, "Hello World" + System.getProperty("line.separator"), "UTF-8", true);
} @Test
public void readingFIleTest() throws IOException {
File file = new File(path);
String content = FileUtils.readFileToString(file, "utf-8");
System.out.println(content);
} @Test
public void copyingFileTest() throws IOException {
File srcFile = new File(path);
File destFile = new File("D:/malin/sss/file.txt");
FileUtils.copyFile(srcFile, destFile);
} @Test
public void deletingFileTest() throws IOException {
FileUtils.deleteDirectory(new File(path).getParentFile());
} @Test
public void convertingTest() throws IOException {
FileUtils.copyURLToFile(new URL("http://www.baidu.com"), new File(path));
}
}
参考
http://commons.apache.org/proper/commons-io/description.html
Apache Common-IO 使用的更多相关文章
- .apache.commons.io 源代码学习(二)FilenameUtils类
FilenameUtils是apache common io中一个独立的工具类,对其他没有依赖,看其源代码的import即可知道. import java.io.File;import java.io ...
- org.apache.common.io-FileUtils详解
org.apache.common.io---FileUtils详解 getTempDirectoryPath():返回临时目录路径; public static String getTempDire ...
- apache commons io包基本功能
1. http://jackyrong.iteye.com/blog/2153812 2. http://www.javacodegeeks.com/2014/10/apache-commons-io ...
- IO与文件读写---使用Apache commons IO包提高读写效率
觉得很不错,就转载了, 作者: Paul Lin 首先贴一段Apache commons IO官网上的介绍,来对这个著名的开源包有一个基本的了解:Commons IO is a library of ...
- apache commons io入门
原文参考 http://www.javacodegeeks.com/2014/10/apache-commons-io-tutorial.html Apache Commons IO 包绝对是 ...
- WEB文件上传之apache common upload使用(一)
文件上传一个经常用到的功能,它有许多中实现的方案. 页面表单 + RFC1897规范 + http协议上传 页面控件(flash/html5/activeX/applet) + RFC1897规范 + ...
- [解决]Hadoop 2.4.1 UnsatisfiedLinkError: org.apache.hadoop.io.nativeio.NativeIO$Windows.access0
问题:UnsatisfiedLinkError: org.apache.hadoop.io.nativeio.NativeIO$Windows.access0 我的系统 win7 64位 Hadoop ...
- SEQ!org.apache.hadoop.io.LongWritable
[uhadoop@10-13-109-236 subdir26]$ $HADOOP_HOME/bin/hadoop fs -cat /data/flumeEvents/FlumeData.155980 ...
- Android中使用Apache common ftp进行下载文件
版权声明:本文为博主原创文章,未经博主同意不得转载. https://blog.csdn.net/birdsaction/article/details/36379201 在Android使用ftp下 ...
- 解决Exception: org.apache.hadoop.io.nativeio.NativeIO$Windows.access0(Ljava/lang/String;I)Z
在项目中添加src中添加NativeIO类 /** * Licensed to the Apache Software Foundation (ASF) under one * or more con ...
随机推荐
- eclipse之插件添加
在ftp.properties文件中,中文出现十六进制显示情况,如下: 解决该问题只需要在eclipse中下载一个插件即可解决, 步骤: help ---> install new softw ...
- 运用CSS3媒体查询判断iPhoneX、iPhoneXR、iPhoneXS MAX及横竖屏
//iphoneX.iphoneXs @media only screen and (device-width: 375px) and (device-height: 812px) and (-web ...
- 解决The Network Adapter could not establish the connection
解决1 主机与虚拟机ping不通 解决2 状态: 失败 -测试失败: IO 错误: The Network Adapter could not establish the connection 本次尝 ...
- Java interface和abstract小记
一.abstract 用abstract修饰的类叫做抽象类,用abstract修饰的方法叫抽象方法. 含有抽象方法的类必须被声明为抽象类,抽象类必须被继承,抽象方法必须被重写. 抽象类不能被实例化. ...
- JFinal常量配置学习笔记
在继承 JFinalConfig 类时,需要 实现 /** * Config constant */ public abstract void configConstant(Constants me) ...
- 服务器 PyTorch 报错 重装 PyTorch
两个代码,pix2pix + CycleGan , wgan-gp 都是 pytorch 写的, 在服务器端运行,均存在下列问题,故判定是 pytorch 的安装问题. Traceback (mos ...
- 新版graylog2安装过程
Graylog是一个开源的 log 收容器,背后的储存是搭配 mongodb,而搜寻引擎则由 elasticsearch 提供.以前版本主要有两个部分集合而成 server 与 web interfa ...
- 利用photoshop制作gif图片
首先准备你需要的几张素材图片 1.将素材图片根据发生的顺序放置在不同的图层 2.打开窗口下的时间轴 选择帧动画 3.创建第一张帧动画 选项卡右边这个按钮,点击这个选择新建帧 第一张图片显示其他的隐藏 ...
- C,通信,多线程,数据库小练习——在线电子词典第一版
#ifndef FILE_H #define FILE_H #include<stdio.h> #include<sys/types.h> #include<sys/so ...
- hdu-1556 Color the ball---树状数组+区间修改单点查询
题目链接: http://acm.hdu.edu.cn/showproblem.php?pid=1556 题目大意: Problem Description N个气球排成一排,从左到右依次编号为1,2 ...