Java文件操作类效率对比
前言
众所周知,Java中有多种针对文件的操作类,以面向字节流和字符流可分为两大类,这里以写入为例:
面向字节流的:FileOutputStream 和 BufferedOutputStream
面向字符流的:FileWriter 和 BufferedWriter
近年来发展出New I/O ,也叫NIO,里面又包装了两个类:NewOutputStream 和 NewBufferedWriter
现在,我们建立测试程序,比较这些类写入文件的性能。
机器配置
- Processor Name: Intel Core i7
- Processor Speed: 2.2 GHz
- Number of Processors: 1
- Total Number of Cores: 4
- L2 Cache (per Core): 256 KB
- L3 Cache: 6 MB
- Memory: 16 GB
测试程序
纵向比较:几种文件操作类向文件中写入相同行数的内容(每行内容均为“写入文件Data\n”),比较其耗费时间
横向比较:对于同一个文件操作类,比较写入不同行数内容情况下所耗费时间;本文以2的次方指数级增长行数
import java.io.File;
import java.io.FileOutputStream;
import java.io.*;
import java.nio.file.Files;
import java.nio.file.Paths; public class testFileIO { public static void testDriver () throws IOException {
int maxlineNum = 100000001;//写入文件的最大行数
int startlineNum = 1;//写入文件的行数
int Multiplying = 2;//行数增长倍率 long begin = 0L;
long end = 0L; //将时间统计写入文件Result.txt中
FileWriter fileWriter = new FileWriter("./Result.txt", true);
BufferedWriter bufferedWriter = new BufferedWriter(fileWriter); System.out.println("Test FileOutputStream begin.");
for (int lineNum = startlineNum; lineNum < maxlineNum; lineNum *= Multiplying) {
begin = System.currentTimeMillis();
testFileOutputStream(lineNum);
end = System.currentTimeMillis();
long timeElapse_FileOutputStream = end - begin;
bufferedWriter.write(String.valueOf(timeElapse_FileOutputStream)+"\t");
}
System.out.println("Test FileOutputStream end.\n"); System.out.println("Test BufferedOutputStream begin.");
bufferedWriter.write("\n");
for (int lineNum = startlineNum; lineNum < maxlineNum; lineNum *= Multiplying) {
begin = System.currentTimeMillis();
testBufferedOutputStream(lineNum);
end = System.currentTimeMillis();
long timeElapse_BufferedOutputStream = end - begin;
bufferedWriter.write(String.valueOf(timeElapse_BufferedOutputStream)+"\t");
}
System.out.println("Test BufferedOutputStream end.\n"); System.out.println("Test FileWriter begin.");
bufferedWriter.write("\n");
for (int lineNum = startlineNum; lineNum < maxlineNum; lineNum *= Multiplying) {
begin = System.currentTimeMillis();
testFileWriter(lineNum);
end = System.currentTimeMillis();
long timeElapse_FileWriter = end - begin;
bufferedWriter.write(String.valueOf(timeElapse_FileWriter)+"\t");
}
System.out.println("Test FileWriter end.\n"); System.out.println("Test BufferedWriter begin.");
bufferedWriter.write("\n");
for (int lineNum = startlineNum; lineNum < maxlineNum; lineNum *= Multiplying) {
begin = System.currentTimeMillis();
testBufferedWriter(lineNum);
end = System.currentTimeMillis();
long timeElapse_BufferedWriter = end - begin;
bufferedWriter.write(String.valueOf(timeElapse_BufferedWriter)+"\t");
}
System.out.println("Test BufferedWriter end.\n"); System.out.println("Test NewOutputStream begin.");
bufferedWriter.write("\n");
for (int lineNum = startlineNum; lineNum < maxlineNum; lineNum *= Multiplying) {
begin = System.currentTimeMillis();
testNewOutputStream(lineNum);
end = System.currentTimeMillis();
long timeElapse_NewOutputStream = end - begin;
bufferedWriter.write(String.valueOf(timeElapse_NewOutputStream)+"\t");
}
System.out.println("Test NewOutputStream end.\n"); System.out.println("Test NewBufferedWriter begin.");
bufferedWriter.write("\n");
for (int lineNum = startlineNum; lineNum < maxlineNum; lineNum *= Multiplying) {
begin = System.currentTimeMillis();
testNewBufferedWriter(lineNum);
end = System.currentTimeMillis();
long timeElapse_NewBufferedWriter = end - begin;
bufferedWriter.write(String.valueOf(timeElapse_NewBufferedWriter)+"\t");
}
System.out.println("Test NewOutputStream end.\n"); bufferedWriter.close();
} /************************** I/O *****************************/
//面向字节
public static void testFileOutputStream (int lineNum) throws IOException {
FileOutputStream fileOutputStream = new FileOutputStream(new File("./testFileOutputStream.txt"));
while (--lineNum > 0) {
fileOutputStream.write("写入文件Data\n".getBytes());
}
fileOutputStream.close();
} public static void testBufferedOutputStream (int lineNum) throws IOException {
FileOutputStream fileOutputStream = new FileOutputStream(new File("./testBufferedOutputStream.txt"));
BufferedOutputStream bufferedOutputStream = new BufferedOutputStream(fileOutputStream);
while (--lineNum > 0) {
bufferedOutputStream.write("写入文件Data\n".getBytes());
}
bufferedOutputStream.close();
} //面向字符
public static void testFileWriter (int lineNum) throws IOException {
FileWriter fileWriter = new FileWriter("./testFileWriter.txt");
while (--lineNum > 0) {
fileWriter.write("写入文件Data\n");
}
fileWriter.close();
} public static void testBufferedWriter (int lineNum) throws IOException {
FileWriter fileWriter = new FileWriter("./testBufferedWriter.txt");
BufferedWriter bufferedWriter = new BufferedWriter(fileWriter);
while (--lineNum > 0) {
bufferedWriter.write("写入文件Data\n");
}
bufferedWriter.close();
} /************************** NIO ****************************/
public static void testNewOutputStream (int lineNum) throws IOException {
OutputStream outputStream = Files.newOutputStream(Paths.get("./testNewOutputStream.txt"));
while (--lineNum > 0) {
outputStream.write("写入文件Data\n".getBytes());
}
outputStream.close();
} public static void testNewBufferedWriter (int lineNum) throws IOException {
BufferedWriter newBufferedReader = Files.newBufferedWriter(Paths.get("./testNewBufferedWriter.txt"));
while (--lineNum > 0) {
newBufferedReader.write("写入文件Data\n");
}
newBufferedReader.close();
} public static void main (String[] args) throws IOException {
//多次测试时可清空result.txt文件
FileWriter fileWriter = new FileWriter("./Result.txt");
testDriver();
}
}
测试结果
从上图可以看出,写入行数超过20W以上时,FileOutputStream和NewOutputStream耗费时间远远超出其他4个类。为了清晰,让我们放大其他4个类的图:
可以看出,这4个类中,BufferWriter和NewBufferedWriter所耗费时间更少,但总体差别不是很大。
让我们再来看看,写入26W行数据以下时的情况:
可以看出,在数据量较小的情况下,这4个类所耗费时间的差异并不是很大,在更小的数据量下,它们的效率几乎没有差别。
后记
从以上分析可知(注意横坐标写入行数是指数级增加的),各个类的时间复杂度大致为O(k),其中不同的类的k不同,导致了最终巨大的差异。
这里只给出了测试结果,并未很深入地分析其底层实现原理,欢迎评论区留言。
另外,我没有在其他机器测试,有兴趣的小伙伴可以将自己的测试结果发出来,共同进步^_^
附件
本次测试数据结果(若看不清,可以将浏览器字体放大,或下载到本地看)
~~~~~~~~~~~~~~~~~~~~~分割线~~~~~~~~~~~~~~~~~~~~~~~
评论区小伙伴“ andorxor”提出:
XXXOutputStream是用来写二进制的,你把字符串转换成字节数组再写自然就慢了,主要慢在转换的过程。
因此,将程序修改,提前把字符和字节内容都准备好,再次验证。新程序如下:
import java.io.File;
import java.io.FileOutputStream;
import java.io.*;
import java.nio.file.Files;
import java.nio.file.Paths; public class testFileIO { public static void testDriver () throws IOException {
int maxlineNum = 100000001;//写入文件的最大行数
int startlineNum = 1;//写入文件的行数
int Multiplying = 2;//行数增长倍率 String contentChars = "写入文件Data\n";//每行的内容(字符流)
byte[] contentBytes = "写入文件Data\n".getBytes();//每行的内容(字节流) long begin = 0L;
long end = 0L; //将时间统计写入文件Result.txt中
FileWriter fileWriter = new FileWriter("./Result.txt", true);
BufferedWriter bufferedWriter = new BufferedWriter(fileWriter); System.out.println("Test FileOutputStream begin.");
for (int lineNum = startlineNum; lineNum < maxlineNum; lineNum *= Multiplying) {
begin = System.currentTimeMillis();
testFileOutputStream(lineNum,contentBytes);
end = System.currentTimeMillis();
long timeElapse_FileOutputStream = end - begin;
bufferedWriter.write(String.valueOf(timeElapse_FileOutputStream)+"\t");
}
System.out.println("Test FileOutputStream end.\n"); System.out.println("Test BufferedOutputStream begin.");
bufferedWriter.write("\n");
for (int lineNum = startlineNum; lineNum < maxlineNum; lineNum *= Multiplying) {
begin = System.currentTimeMillis();
testBufferedOutputStream(lineNum,contentBytes);
end = System.currentTimeMillis();
long timeElapse_BufferedOutputStream = end - begin;
bufferedWriter.write(String.valueOf(timeElapse_BufferedOutputStream)+"\t");
}
System.out.println("Test BufferedOutputStream end.\n"); System.out.println("Test FileWriter begin.");
bufferedWriter.write("\n");
for (int lineNum = startlineNum; lineNum < maxlineNum; lineNum *= Multiplying) {
begin = System.currentTimeMillis();
testFileWriter(lineNum,contentChars);
end = System.currentTimeMillis();
long timeElapse_FileWriter = end - begin;
bufferedWriter.write(String.valueOf(timeElapse_FileWriter)+"\t");
}
System.out.println("Test FileWriter end.\n"); System.out.println("Test BufferedWriter begin.");
bufferedWriter.write("\n");
for (int lineNum = startlineNum; lineNum < maxlineNum; lineNum *= Multiplying) {
begin = System.currentTimeMillis();
testBufferedWriter(lineNum,contentChars);
end = System.currentTimeMillis();
long timeElapse_BufferedWriter = end - begin;
bufferedWriter.write(String.valueOf(timeElapse_BufferedWriter)+"\t");
}
System.out.println("Test BufferedWriter end.\n"); System.out.println("Test NewOutputStream begin.");
bufferedWriter.write("\n");
for (int lineNum = startlineNum; lineNum < maxlineNum; lineNum *= Multiplying) {
begin = System.currentTimeMillis();
testNewOutputStream(lineNum,contentBytes);
end = System.currentTimeMillis();
long timeElapse_NewOutputStream = end - begin;
bufferedWriter.write(String.valueOf(timeElapse_NewOutputStream)+"\t");
}
System.out.println("Test NewOutputStream end.\n"); System.out.println("Test NewBufferedWriter begin.");
bufferedWriter.write("\n");
for (int lineNum = startlineNum; lineNum < maxlineNum; lineNum *= Multiplying) {
begin = System.currentTimeMillis();
testNewBufferedWriter(lineNum,contentChars);
end = System.currentTimeMillis();
long timeElapse_NewBufferedWriter = end - begin;
bufferedWriter.write(String.valueOf(timeElapse_NewBufferedWriter)+"\t");
}
System.out.println("Test NewOutputStream end.\n"); bufferedWriter.close();
} /************************** I/O *****************************/
//面向字节
public static void testFileOutputStream (int lineNum, byte[] content) throws IOException {
FileOutputStream fileOutputStream = new FileOutputStream(new File("./testFileOutputStream.txt"));
while (--lineNum > 0) {
fileOutputStream.write(content);
}
fileOutputStream.close();
} public static void testBufferedOutputStream (int lineNum, byte[] content) throws IOException {
FileOutputStream fileOutputStream = new FileOutputStream(new File("./testBufferedOutputStream.txt"));
BufferedOutputStream bufferedOutputStream = new BufferedOutputStream(fileOutputStream);
while (--lineNum > 0) {
bufferedOutputStream.write(content);
}
bufferedOutputStream.close();
} //面向字符
public static void testFileWriter (int lineNum, String content) throws IOException {
FileWriter fileWriter = new FileWriter("./testFileWriter.txt");
while (--lineNum > 0) {
fileWriter.write(content);
}
fileWriter.close();
} public static void testBufferedWriter (int lineNum, String content) throws IOException {
FileWriter fileWriter = new FileWriter("./testBufferedWriter.txt");
BufferedWriter bufferedWriter = new BufferedWriter(fileWriter);
while (--lineNum > 0) {
bufferedWriter.write(content);
}
bufferedWriter.close();
} /************************** NIO ****************************/
public static void testNewOutputStream (int lineNum, byte[] content) throws IOException {
OutputStream outputStream = Files.newOutputStream(Paths.get("./testNewOutputStream.txt"));
while (--lineNum > 0) {
outputStream.write(content);
}
outputStream.close();
} public static void testNewBufferedWriter (int lineNum,String content) throws IOException {
BufferedWriter newBufferedReader = Files.newBufferedWriter(Paths.get("./testNewBufferedWriter.txt"));
while (--lineNum > 0) {
newBufferedReader.write(content);
}
newBufferedReader.close();
} public static void main (String[] args) throws IOException {
//多次测试时可清空result.txt文件
FileWriter fileWriter = new FileWriter("./Result.txt");
testDriver();
}
}
结果为:
可以看出和前面的案例几乎没有差异(图就不画了)。
所以XXXOutputStream效率低的原因并不是字符串转换成字节数组,而是其本身的实现方式所致。
~~~~~~~~~~~~~~~~~~~~~分割线:底层实现原理浅谈~~~~~~~~~~~~~~~~~~~~~~~
其实,计算机中都是针对字节操作的(即字符都要经过编码转换为字节),那么问题来了,FileOutputStream为什么比FileWriter(FileWriter内部还有FileOutputStream转换操作,具体看源码)还要慢呢?且慢,让我们把写入文件的数据改一下:
import java.io.File;
import java.io.FileOutputStream;
import java.io.*;
import java.nio.file.Files;
import java.nio.file.Paths; public class testFileIO { public static void testDriver () throws IOException {
int maxlineNum = 500001;//写入文件的最大行数
int startlineNum = 1;//写入文件的行数
int Multiplying = 2;//行数增长倍率 String baseContent = "背景\n" +
"考虑以下场景:\n" +
"\n" +
"InfoTable(信息表):\n" +
"\n" +
"Name\tGender\tAge\tScore\n" +
"张三\t男\t21\t90\n" +
"李四\t女\t20\t87\n" +
"王五\t男\t22\t92\n" +
"赵六\t女\t19\t94\n" +
"孙七\t女\t23\t88\n" +
"周八\t男\t20\t91\n" +
"StatusTable(状态表,指是否有在考试之前复习):\n" +
"\n" +
"Name\thasReview\n" +
"张三\t是\n" +
"李四\t否\n" +
"王五\t是\n" +
"赵六\t是\n" +
"孙七\t否\n" +
"周八\t是\n" +
"现在,我想知道所有复习过的学生的成绩,可以利用mysql中的子查询来实现:\n" +
"\n" +
"SELECT Score \n" +
"FROM InfoTable \n" +
"WHERE Name in (SELECT Name \n" +
" FROM StatusTable \n" +
" WHERE hasReview = '是');\n" +
"这种方式非常方便,我们只要把查询条件写出来,剩下的操作都由mysql来处理。而在实际场景中,为了减少底层耦合,我们一般不通过mysql中的子查询方式联表查询,而是先执行子查询得到结果集,再以结果集作为条件执行外层查询。通常情况下,子查询和外层查询由上层的不同服务执行,这样就在一定程度上达到了底层数据库解耦的目的。注意这种实现方式将mysql内部的一部分复杂操作抛给了我们。这时,Mybatis中的foreach标签就有了用武之地。\n" +
"\n" +
"Mybatis 中foreach标签的用法\n" +
"还以刚才的例子来说,先执行子查询\n" +
"\n" +
"SELECT Name FROM StatusTable WHERE hasReview = '是'\n" +
"再执行外层查询,就是\n" +
"\n" +
"SELECT Score \n" +
"FROM InfoTable \n" +
"WHERE Name in ('张三' , '王五', '赵六', '周八');\n" +
"也就是一个批量查询操作,将其抽象一下(假设有三个条件):\n" +
"\n" +
"SELECT * \n" +
"FROM <tableName> \n" +
"WHERE <ColumnName> IN (<case1>,<case2>,<case3>)\n" +
"实际情况中,case可能远不止3个,这时可以在XXXMapper.xml文件中利用Mybatis中的foreach编写sql语句:\n" +
"\n" +
"SELECT * \n" +
"FROM <tableName> \n" +
"WHERE <ColumnName> IN \n" +
"<foreach collection=\"list\" index=\"index\" item=\"item\" open=\"(\" separator=\",\" close=\")\">\n" +
" #{item}\n" +
"</foreach>\n" +
"就可以实现相同的效果了。\n" +
"\n" +
"那么问题来了,foreach标签中各种参数是什么含义呢?\n" +
"\n" +
"collection\n" +
"如果传入的是单参数且参数类型是一个List的时候,collection属性值为list\n" +
"如果传入的是单参数且参数类型是一个array数组的时候,collection的属性值为array\n" +
"如果传入的参数是多个的时候,我们就需要把它们封装成一个Map了,当然单参数也可以封装成map,实际上如果你在传入参数的时候,在breast里面也是会把它封装成一个Map的,map的key就是参数名,所以这个时候collection属性值就是传入的List或array对象在自己封装的map里面的key\n" +
"index 集合迭代位置\n" +
"item 集合中的每一个元素别名\n" +
"open 开始符号,例如这里的(,就对应于IN (<case1>,<case2>,<case3>)中IN后面的第一个(\n" +
"separator 分隔符,例如这里的,,就对应于IN (<case1>,<case2>,<case3>)中的,\n" +
"close 结束符号,例如这里的),就对应于IN (<case1>,<case2>,<case3>)中<case3>后面的)\n" +
"参考\n"; String contentChars = baseContent;//每行的内容(字符流)
byte[] contentBytes = baseContent.getBytes();//每行的内容(字节流) long begin = 0L;
long end = 0L; //将时间统计写入文件Result.txt中
FileWriter fileWriter = new FileWriter("./Result.txt", true);
BufferedWriter bufferedWriter = new BufferedWriter(fileWriter); System.out.println("Test FileOutputStream begin.");
for (int lineNum = startlineNum; lineNum < maxlineNum; lineNum *= Multiplying) {
begin = System.currentTimeMillis();
testFileOutputStream(lineNum,contentBytes);
end = System.currentTimeMillis();
long timeElapse_FileOutputStream = end - begin;
bufferedWriter.write(String.valueOf(timeElapse_FileOutputStream)+"\t");
}
System.out.println("Test FileOutputStream end.\n"); System.out.println("Test BufferedOutputStream begin.");
bufferedWriter.write("\n");
for (int lineNum = startlineNum; lineNum < maxlineNum; lineNum *= Multiplying) {
begin = System.currentTimeMillis();
testBufferedOutputStream(lineNum,contentBytes);
end = System.currentTimeMillis();
long timeElapse_BufferedOutputStream = end - begin;
bufferedWriter.write(String.valueOf(timeElapse_BufferedOutputStream)+"\t");
}
System.out.println("Test BufferedOutputStream end.\n"); System.out.println("Test FileWriter begin.");
bufferedWriter.write("\n");
for (int lineNum = startlineNum; lineNum < maxlineNum; lineNum *= Multiplying) {
begin = System.currentTimeMillis();
testFileWriter(lineNum,contentChars);
end = System.currentTimeMillis();
long timeElapse_FileWriter = end - begin;
bufferedWriter.write(String.valueOf(timeElapse_FileWriter)+"\t");
}
System.out.println("Test FileWriter end.\n"); System.out.println("Test BufferedWriter begin.");
bufferedWriter.write("\n");
for (int lineNum = startlineNum; lineNum < maxlineNum; lineNum *= Multiplying) {
begin = System.currentTimeMillis();
testBufferedWriter(lineNum,contentChars);
end = System.currentTimeMillis();
long timeElapse_BufferedWriter = end - begin;
bufferedWriter.write(String.valueOf(timeElapse_BufferedWriter)+"\t");
}
System.out.println("Test BufferedWriter end.\n"); System.out.println("Test NewOutputStream begin.");
bufferedWriter.write("\n");
for (int lineNum = startlineNum; lineNum < maxlineNum; lineNum *= Multiplying) {
begin = System.currentTimeMillis();
testNewOutputStream(lineNum,contentBytes);
end = System.currentTimeMillis();
long timeElapse_NewOutputStream = end - begin;
bufferedWriter.write(String.valueOf(timeElapse_NewOutputStream)+"\t");
}
System.out.println("Test NewOutputStream end.\n"); System.out.println("Test NewBufferedWriter begin.");
bufferedWriter.write("\n");
for (int lineNum = startlineNum; lineNum < maxlineNum; lineNum *= Multiplying) {
begin = System.currentTimeMillis();
testNewBufferedWriter(lineNum,contentChars);
end = System.currentTimeMillis();
long timeElapse_NewBufferedWriter = end - begin;
bufferedWriter.write(String.valueOf(timeElapse_NewBufferedWriter)+"\t");
}
System.out.println("Test NewOutputStream end.\n"); bufferedWriter.close();
} /************************** I/O *****************************/
//面向字节
public static void testFileOutputStream (int lineNum, byte[] content) throws IOException {
FileOutputStream fileOutputStream = new FileOutputStream(new File("./testFileOutputStream.txt"));
while (--lineNum > 0) {
fileOutputStream.write(content);
}
fileOutputStream.close();
} public static void testBufferedOutputStream (int lineNum, byte[] content) throws IOException {
FileOutputStream fileOutputStream = new FileOutputStream(new File("./testBufferedOutputStream.txt"));
BufferedOutputStream bufferedOutputStream = new BufferedOutputStream(fileOutputStream);
while (--lineNum > 0) {
bufferedOutputStream.write(content);
}
bufferedOutputStream.close();
} //面向字符
public static void testFileWriter (int lineNum, String content) throws IOException {
FileWriter fileWriter = new FileWriter("./testFileWriter.txt");
while (--lineNum > 0) {
fileWriter.write(content);
}
fileWriter.close();
} public static void testBufferedWriter (int lineNum, String content) throws IOException {
FileWriter fileWriter = new FileWriter("./testBufferedWriter.txt");
BufferedWriter bufferedWriter = new BufferedWriter(fileWriter);
while (--lineNum > 0) {
bufferedWriter.write(content);
}
bufferedWriter.close();
} /************************** NIO ****************************/
public static void testNewOutputStream (int lineNum, byte[] content) throws IOException {
OutputStream outputStream = Files.newOutputStream(Paths.get("./testNewOutputStream.txt"));
while (--lineNum > 0) {
outputStream.write(content);
}
outputStream.close();
} public static void testNewBufferedWriter (int lineNum,String content) throws IOException {
BufferedWriter newBufferedReader = Files.newBufferedWriter(Paths.get("./testNewBufferedWriter.txt"));
while (--lineNum > 0) {
newBufferedReader.write(content);
}
newBufferedReader.close();
} public static void main (String[] args) throws IOException {
//多次测试时可清空result.txt文件
FileWriter fileWriter = new FileWriter("./Result.txt");
testDriver();
}
}
这次数据量就很大了,结果也就变了:
所以,数据量很小的情况下,字符到字节的编码操作带来的性能降低几乎忽略不计;而数据量很大的时候,编码耗费的时间就很可观了。至于为什么在小数据量的情况下FileWriter快很多,目前我认为是一次操作两个字节所致(有了缓存之后就差不多了)。
参考
Java文件操作类效率对比的更多相关文章
- JAVA文件操作类和文件夹的操作代码示例
JAVA文件操作类和文件夹的操作代码实例,包括读取文本文件内容, 新建目录,多级目录创建,新建文件,有编码方式的文件创建, 删除文件,删除文件夹,删除指定文件夹下所有文件, 复制单个文件,复制整个文件 ...
- java中多种写文件方式的效率对比实验
一.实验背景 最近在考虑一个问题:“如果快速地向文件中写入数据”,java提供了多种文件写入的方式,效率上各有异同,基本上可以分为如下三大类:字节流输出.字符流输出.内存文件映射输出.前两种又可以分为 ...
- java csv 文件 操作类
一个CSV文件操作类,功能比较齐全: package tool; import java.io.BufferedReader; import java.io.BufferedWriter; impor ...
- Java文件操作源码大全
Java文件操作源码大全 1.创建文件夹 52.创建文件 53.删除文件 54.删除文件夹 65.删除一个文件下夹所有的文件夹 76.清空文件夹 87.读取文件 88.写入文件 99.写入随机文件 9 ...
- android 文件操作类简易总结
android 文件操作类(参考链接) http://www.cnblogs.com/menlsh/archive/2013/04/02/2997084.html package com.androi ...
- C# 文件操作类大全
C# 文件操作类大全 时间:2015-01-31 16:04:20 阅读:1724 评论:0 收藏:0 [点我收藏+] 标签: 1.创建文件夹 //usin ...
- Android FileUtils 文件操作类
系统路径 Context.getPackageName(); // 用于获取APP的所在包目录 Context.getPackageCodePath(); //来获得当前应用程序对应的apk文件的路径 ...
- File 文件操作类 大全
File 文件操作类 大全 许多人都会对文件操作感到很难 我也是 但是一个好的项目中必定会涉及到文件操作的 文件的复制 粘贴 等等等 公司大佬写了 一个文件操作的工具类 感觉还是棒棒的啦 ...
- 14、Java文件操作stream、File、IO
1.文件操作涉及到的基本概念 File File类 是文件操作的主要对象中文意义就是 文件 顾名思意 万物皆文件,在计算上看到的所有东西都是文件保存,不管是你的图片.视频.数据库数据等等都是按照基本的 ...
随机推荐
- 打开xmind 8 输入序列号
XAka34A2rVRYJ4XBIU35UZMUEEF64CMMIYZCK2FZZUQNODEKUHGJLFMSLIQMQUCUBXRENLK6NZL37JXP4PZXQFILMQ2RG5R7G4QN ...
- [转] Introduction to AppArmor
Introduction to AppArmor http://ubuntuforums.org/showthread.php?t=1008906 Contents Post 1 Introducti ...
- react-native 项目初始化
react-native 项目初始化 搭建java,android,node环境 http://www.cnblogs.com/morang/p/react-native-java-build.htm ...
- eclipse中如何自动生成构造函数
eclipse中如何自动生成构造函数 eclipse是一个非常好的IDE,我在写java程序的时候使用eclipse感觉开发效率很高.而且有很多的快捷和简便方式供大家使用,并且能直接生成class文件 ...
- Java中最常用的集合类框架之 HashMap
一.HashMap的概述 HashMap可以说是Java中最常用的集合类框架之一,是Java语言中非常典型的数据结构. HashMap是基于哈希表的Map接口实现的,此实现提供所有可选的映射 ...
- 如何优化Spring Cloud微服务注册中心架构?
作者: 石杉的架构笔记 1.再回顾:什么是服务注册中心? 先回顾一下什么叫做服务注册中心? 顾名思义,假设你有一个分布式系统,里面包含了多个服务,部署在不同的机器上,然后这些不同机器上的服务之间要互相 ...
- Java学到什么程度才能叫精通?
把下面这些内容掌握以后,你就可以自诩精通Java后端了. 1 计算机基础 这部分内容是计算机相关专业同学的课程,但是非科班的小伙伴(譬如在下)就需要花时间恶补了. 特别 是计算机网络,操作系统 ...
- Day10:html和css
Day10:html和css <html> <body> <h1>标题</h1> <p>段落</p> </body> ...
- 树莓派MQTT客户端搭建
树莓派安装和实现MQTT协议 下载Mosquitto 更新软件源:sudo apt-get update 下载g++编译器:sudo apt-get install g++ 安装:sudo apt- ...
- FTP服务器搭建与访问的相关问题
近期想搭建在云服务器上搭建一个项目,每次远程登陆服务器实在比较繁琐,故而想到使用FTP上传下载方式来进行相应的操作:在网络上搭建FTP服务器的文档还是很丰富的,按照操作一步步来还算方便,楼主就不在这边 ...