java:24G文件写入所要时间23.9分,读取只有67秒(1G内存测试)
2010-05-17 12:20
639 查看
package arrays.file;
import java.io.BufferedReader;
import java.io.BufferedWriter;
import java.io.FileReader;
import java.io.FileWriter;
import java.io.IOException;
public class WriteFile {
public static void main(String[] args) {
String path = "d:/data.txt";
writerFile(path);
readerFile(path);
}
// 写入文件
public static void writerFile(String path) {
try {
BufferedWriter bw = new BufferedWriter(new FileWriter(path));
// int max = Integer.MAX_VALUE;
int max = 1000;
System.out.println("总写入文件行数:" + max);
long start = System.currentTimeMillis();
for (int i = 0; i < max; i++) {
bw.write((int) (Math.random() * max) + "");
bw.newLine();
}
bw.close();
long end = System.currentTimeMillis();
System.out.println("写入耗时:" + (end - start) + "ms = "
+ ((double) (end - start) / 1000) + "s");
} catch (IOException e) {
e.printStackTrace();
}
}
// 读取文件
public static void readerFile(String path) {
try {
BufferedReader br = new BufferedReader(new FileReader(path));
long start = System.currentTimeMillis();
while (br.ready()) {
br.readLine();
}
br.close();
long end = System.currentTimeMillis();
System.out.println("读取耗时:" + (end - start) + "ms = "
+ ((double) (end - start) / 1000) + "s");
} catch (IOException e) {
e.printStackTrace();
}
}
// 分割文件
public static void splitFile() {
}
}
import java.io.BufferedReader;
import java.io.BufferedWriter;
import java.io.FileReader;
import java.io.FileWriter;
import java.io.IOException;
public class WriteFile {
public static void main(String[] args) {
String path = "d:/data.txt";
writerFile(path);
readerFile(path);
}
// 写入文件
public static void writerFile(String path) {
try {
BufferedWriter bw = new BufferedWriter(new FileWriter(path));
// int max = Integer.MAX_VALUE;
int max = 1000;
System.out.println("总写入文件行数:" + max);
long start = System.currentTimeMillis();
for (int i = 0; i < max; i++) {
bw.write((int) (Math.random() * max) + "");
bw.newLine();
}
bw.close();
long end = System.currentTimeMillis();
System.out.println("写入耗时:" + (end - start) + "ms = "
+ ((double) (end - start) / 1000) + "s");
} catch (IOException e) {
e.printStackTrace();
}
}
// 读取文件
public static void readerFile(String path) {
try {
BufferedReader br = new BufferedReader(new FileReader(path));
long start = System.currentTimeMillis();
while (br.ready()) {
br.readLine();
}
br.close();
long end = System.currentTimeMillis();
System.out.println("读取耗时:" + (end - start) + "ms = "
+ ((double) (end - start) / 1000) + "s");
} catch (IOException e) {
e.printStackTrace();
}
}
// 分割文件
public static void splitFile() {
}
}
相关文章推荐
- java:24G文件写入所要时间23.9分,读取只有67秒(1G内存测试)
- java:24G文件写入所要时间23.9分,读取只有67秒(1G内存测试)
- 使用Java读取xlxs文件和写入txt文件,并将数据写入到本地文件
- java文件写入与读取
- java按指定编码写入和读取文件内容的类
- java写入Excel并读取文件
- Java读取txt文件和写入txt文件
- Java-文件读取写入整型(字节流)
- java中经常用到的读写配置文件的信息properties属性的写入,读取例子
- java IO流处理实战;完成文件读取和写入,使用到BufferedReader 、PrintStream等
- java 文件操作 写入和读取(小结一)
- java按指定编码写入和读取文件内容的类
- Java 读取目录下文件(按修改时间返回文件顺序)
- Java文件读取写入后 md5值不变的实现方法
- JAVA 创建TXT文件,写入文件内容,读取文件内容
- 测试用指定块大小读取文件时间的代码
- java使用CsvReader和CsvWriter对csv文件内容进行读取和写入操作
- java文件之写入,读取,全部删除,获取过滤or获取特定字符串,删除特定字符串方法集合
- Java底层代码实现多文件读取和写入
- java 将对象写入文件进行保存和读取