package com.dne;
import java.io.BufferedReader;
import java.io.FileInputStream;
import java.io.FileNotFoundException;
import java.io.FileOutputStream;
import java.io.FileReader;
import java.io.IOException;
import java.io.InputStreamReader;
import java.io.OutputStream;
import java.io.OutputStreamWriter;
import java.text.DateFormat;
import java.util.Date;
import com.dne.core.util.DateUtil;
public class IBM_Thread {
static int i = 0;
public static void main(String args[]){
new MyThread().run();
i = 2;
}
public static class MyThread extends Thread{
@Override
public void run() {
// TODO Auto-generated method stub
try {
DateFormat dateFormt = DateUtil.getCnDateFormat("yyyy-MM-dd HH:mm:ss SSS");
System.out.println("--------inputStream--------\n\n\n");
System.out.println("--------BufferedReader < inputStreamReader--------\n\n\n");
{
System.out.println("start:"+dateFormt.format(new Date()));
//为了达到最高效率,可要考虑在 BufferedReader 内包装 InputStreamReader
BufferedReader bufferedReader = new BufferedReader(new InputStreamReader(new FileInputStream("D:\\cn_visual_studio_2010.iso"), "UTF-8"));
char[] ch= new char[1024*10];
StringBuffer sb = new StringBuffer();
int result = -1;
while((result = bufferedReader.read(ch))!=-1){
sb.append(ch, 0, result);
sb.reverse();
}
bufferedReader.close();
//System.out.println(new String(sb.toString().getBytes(),"UTF-8"));
System.out.println("end:"+dateFormt.format(new Date()));
}
System.out.println("--------FileReader--------\n\n\n\n");
{
System.out.println("start:"+dateFormt.format(new Date()));
//FileReader 用于读取字符流。要读取原始字节流,请考虑使用 FileInputStream
FileReader fileReader = new FileReader("D:\\cn_visual_studio_2010_ultimate_x86_dvd_532347.iso");
StringBuffer sb = new StringBuffer();
char[] ch = new char[1024*10];
int result = -1;
while((result = fileReader.read(ch))!=-1){
sb.append(ch, 0, result);
sb.reverse();
}
//System.out.println(new String(sb.toString().getBytes(),"UTF-8"));
System.out.println("end:"+dateFormt.format(new Date()));
}
System.out.println("--------inputStreamReader--------\n\n\n");
{
System.out.println("start:"+dateFormt.format(new Date()));
//InputStreamReader 类是字节到字符的转化桥梁
InputStreamReader inputStreamReader = new InputStreamReader(new FileInputStream("D:\\cn_visual_studio_2010.iso"), "UTF-8");
char[] ch= new char[1024*10];
StringBuffer sb = new StringBuffer();
int result = -1;
while((result = inputStreamReader.read(ch))!=-1){
sb.append(ch, 0, result);
sb.reverse();
}
inputStreamReader.close();
//System.out.println(new String(sb.toString().getBytes(),"UTF-8"));
System.out.println("end:"+dateFormt.format(new Date()));
}
System.out.println("--------outputStream--------\n\n\n");
{
System.out.println("start:"+dateFormt.format(new Date()));
OutputStream outputStream = new FileOutputStream("C:\\input__.xml");
char[] ch = new char[1024*10];
OutputStreamWriter outputStreamWriter = new OutputStreamWriter(outputStream);
InputStreamReader inputStreamReader = new InputStreamReader(new FileInputStream("C:\\input.xml"), "UTF-8");
int result = -1;
while((result = inputStreamReader.read(ch))!=-1){
outputStreamWriter.write(ch, 0, result);
}
outputStreamWriter.close();
inputStreamReader.close();
outputStreamWriter.close();
System.out.println("end:"+dateFormt.format(new Date()));
}
} catch (FileNotFoundException e) {
// TODO Auto-generated catch block
e.printStackTrace();
} catch (IOException e) {
// TODO Auto-generated catch block
e.printStackTrace();
}
}
};
}
字节字符流
最新推荐文章于 2024-09-11 22:27:53 发布