InputStream && OutputStream:
InputStreamReader&& OutputStreamWriter:
BufferedInputStream && BufferedOutputStream:
BufferedReader && BufferedWriter
FileInputStream && FileOutputStream
FileReader && FileWriter
还有很多。。。更新中。。。
private static void rwIOStream() throws Exception {
InputStream in =new FileInputStream("fileIn\\txt1");
OutputStream out = new FileOutputStream("fileOut\\txt1");
int len;
long begin = System.currentTimeMillis();
while((len=in.read())!=-1)
{
out.write(len);
}
long end = System.currentTimeMillis();
System.out.println(end-begin);
in.close();
out.close();
}
private static void rwIOStreamRW() throws Exception {
InputStreamReader inReader =new InputStreamReader(new FileInputStream("fileIn\\txt1"));
OutputStreamWriter outWriter =new OutputStreamWriter(new FileOutputStream("fileIn\\txt1"));
int len;
long begin = System.currentTimeMillis();
while((len=inReader.read())!=-1)
{
outWriter.write(len);
}
long end = System.currentTimeMillis();
System.out.println(end-begin);
inReader.close();
outWriter.close();
}
private static void rwBufferedIOStram() throws Exception {
BufferedInputStream in = new BufferedInputStream(new FileInputStream("fileIn\\txt1"));
BufferedOutputStream out = new BufferedOutputStream(new FileOutputStream("fileOut\\txt1"));
long begin = System.currentTimeMillis();
int len;
while((len=in.read())!=-1)
{
out.write(len);
//System.out.print((char)len); // 字符打印
}
long end = System.currentTimeMillis();
System.out.println(end-begin);
in.close();
out.close();
}
private static void rwBufferedRWr() throws Exception {
BufferedReader reader = new BufferedReader(new FileReader("fileIn\\txt1"));
BufferedWriter writer = new BufferedWriter(new FileWriter("fileIn\\txt1"));
int len;
long begin = System.currentTimeMillis();
while((len = reader.read())!=-1)
{
writer.write(len);
//System.out.print((char)len);
}
long end = System.currentTimeMillis();
System.out.println(end-begin);
reader.close();
writer.close();
}
private static void rwFileIOStream() throws Exception {
FileInputStream reader = new FileInputStream("fileIn\\txt1");
FileOutputStream writer = new FileOutputStream("fileIn\\txt1");
int len;
long begin = System.currentTimeMillis();
while((len = reader.read())!=-1)
{
writer.write(len);
//System.out.print((char)len);
}
long end = System.currentTimeMillis();
System.out.println(end-begin);
reader.close();
writer.close();
}
private static void rwFile() throws Exception {
FileReader reader = new FileReader("fileIn\\txt1");
FileWriter writer = new FileWriter("fileOut\\txt1");
int len;
long begin = System.currentTimeMillis();
while((len = reader.read())!=-1)
{
writer.write(len);
//System.out.print((char)len);
}
long end = System.currentTimeMillis();
System.out.println(end-begin);
reader.close();
writer.close();
}
package file;
import java.io.BufferedInputStream;
import java.io.BufferedOutputStream;
import java.io.BufferedReader;
import java.io.BufferedWriter;
import java.io.FileInputStream;
import java.io.FileNotFoundException;
import java.io.FileOutputStream;
import java.io.FileReader;
import java.io.FileWriter;
import java.io.IOException;
import java.io.InputStream;
import java.io.InputStreamReader;
import java.io.OutputStream;
import java.io.OutputStreamWriter;
public class filecopy {
public static void main(String[] avg) throws Exception
{
try {
//复制例
song();
//字符读写 切割处理
rwFileSplitEnglish();
//InputStream && OutputStream
rwIOStream();
//InputStreamReader && OutputStreamWriter
rwIOStreamRW();
//BufferedInputStream && BufferedOutputStream
rwBufferedIOStram();
//BufferedReader && BufferedWriter
rwBufferedRWr();
//FileInputStream && FileOutputStream
rwFileIOStream();
//FileReader && FileWriter
rwFile();
} catch (Exception e) {
e.printStackTrace();
}
}
private static void rwIOStream() throws Exception {
InputStream in =new FileInputStream("fileIn\\txt1");
OutputStream out = new FileOutputStream("fileOut\\txt1");
int len;
long begin = System.currentTimeMillis();
while((len=in.read())!=-1)
{
out.write(len);
}
long end = System.currentTimeMillis();
System.out.println(end-begin);
in.close();
out.close();
}
private static void rwIOStreamRW() throws Exception {
InputStreamReader inReader =new InputStreamReader(new FileInputStream("fileIn\\txt1"));
OutputStreamWriter outWriter =new OutputStreamWriter(new FileOutputStream("fileIn\\txt1"));
int len;
long begin = System.currentTimeMillis();
while((len=inReader.read())!=-1)
{
outWriter.write(len);
}
long end = System.currentTimeMillis();
System.out.println(end-begin);
inReader.close();
outWriter.close();
}
private static void rwBufferedIOStram() throws Exception {
BufferedInputStream in = new BufferedInputStream(new FileInputStream("fileIn\\txt1"));
BufferedOutputStream out = new BufferedOutputStream(new FileOutputStream("fileOut\\txt1"));
long begin = System.currentTimeMillis();
int len;
while((len=in.read())!=-1)
{
out.write(len);
//System.out.print((char)len); // 字符打印
}
long end = System.currentTimeMillis();
System.out.println(end-begin);
in.close();
out.close();
}
private static void rwBufferedRWr() throws Exception {
BufferedReader reader = new BufferedReader(new FileReader("fileIn\\txt1"));
BufferedWriter writer = new BufferedWriter(new FileWriter("fileIn\\txt1"));
int len;
long begin = System.currentTimeMillis();
while((len = reader.read())!=-1)
{
writer.write(len);
//System.out.print((char)len);
}
long end = System.currentTimeMillis();
System.out.println(end-begin);
reader.close();
writer.close();
}
private static void rwFileIOStream() throws Exception {
FileInputStream reader = new FileInputStream("fileIn\\txt1");
FileOutputStream writer = new FileOutputStream("fileIn\\txt1");
int len;
long begin = System.currentTimeMillis();
while((len = reader.read())!=-1)
{
writer.write(len);
//System.out.print((char)len);
}
long end = System.currentTimeMillis();
System.out.println(end-begin);
reader.close();
writer.close();
}
private static void rwFile() throws Exception {
FileReader reader = new FileReader("fileIn\\txt1");
FileWriter writer = new FileWriter("fileOut\\txt1");
int len;
long begin = System.currentTimeMillis();
while((len = reader.read())!=-1)
{
writer.write(len);
//System.out.print((char)len);
}
long end = System.currentTimeMillis();
System.out.println(end-begin);
reader.close();
writer.close();
}
private static void rwFileSplitEnglish() throws Exception {
String str = "";
FileReader reader = new FileReader("fileIn\\txt1");
int len;
while((len = reader.read())!=-1)
str +=(char)len;
reader.close();
System.out.println(str);
String re = " ";
String s[] = str.split(re);
for (int i = 0; i < s.length; i++) {
System.out.print(s[i]);
}
System.out.println(str.length());
}
private static void song() throws Exception {
InputStream in = new FileInputStream("fileIn\\你一生的故事.mp3");
OutputStream out = new FileOutputStream("fileOut\\你一生的故事2.mp3");
int len;
long begintime = System.currentTimeMillis();
while((len=in.read())!=-1)
{
out.write(len);
}
long endtime = System.currentTimeMillis();
System.out.println(endtime-begintime);
in.close();
out.close();
}
}