标签:
//第一步,导入类
import java.io.*;
classTest{
publicstaticvoid main(String args []){
//声明输入流引用
FileInputStream fis = null;
try{
//生成代表输入流的对象
fis =newFileInputStream("D:/work/src/from.txt");
//生成一个字节数组
byte [] buffer =new byte[10];
//调用输入流对象的read方法,读取数据
fis.read(buffer,0,buffer.length);
for(int i =0; i < buffer.length; i++){
System.out.println(buffer[i]);
}
}
catch(Exception e){
System.out.println(e);
}
}
}
//第一步,导入类
import java.io.*;
classTest{
publicstaticvoid main(String args []){
//声明输入流引用
FileInputStream fis = null;
//声明输出流的引用
FileOutputStream fos = null;
try{
//生成代表输入流的对象
fis =newFileInputStream("D:/work/src/from.txt");
//生成代表输出流的对象
fos =newFileOutputStream("D:/work/src/to.txt");
//生成一个字节数组
byte [] buffer =new byte[10];
//调用输入流对象的read方法,读取数据
int temp = fis.read(buffer,0,buffer.length);
fos.write(buffer,0,temp);
//String a = new String(buffer);
//调用一个Strng对象的trim方法,将会去掉这个字符串
//的首位空格和空字符
//s = s.trim();
//System.out.println(s);
}
catch(Exception e){
System.out.println(e);
}
}
}
//第一步,导入类
import java.io.*;
classTest{
publicstaticvoid main(String args []){
//声明输入流引用
FileInputStream fis = null;
//声明输出流的引用
FileOutputStream fos = null;
try{
//生成代表输入流的对象
fis =newFileInputStream("D:/work/src/from.txt");
//生成代表输出流的对象
fos =newFileOutputStream("D:/work/src/to.txt");
//生成一个字节数组
byte [] buffer =new byte[1024];
while(true){
//调用输入流对象的read方法,读取数据
int temp = fis.read(buffer,0,buffer.length);
if(temp ==-1){
break;
}
fos.write(buffer,0,temp);
}
//String a = new String(buffer);
//调用一个Strng对象的trim方法,将会去掉这个字符串
//的首位空格和空字符
//s = s.trim();
//System.out.println(s);
}
catch(Exception e){
System.out.println(e);
}
finally{
//捕获关闭IO流可能出现的异常
try{
fis.close();
fos.close();
}
catch(Exception e){
System.out.println(e);
}
}
}
}
//int writer(char [] c,int off,int len)
import java.io.*;
publicclassTestChar{
publicstaticvoid main(String args []){
FileReader fr = null;
FileWriter fw = null;
try{
fr =newFileReader("D:/work/src/from.txt");
fw =newFileWriter("D:/work/src/to.txt");
char[] buffer =newchar[100];
int temp = fr.read(buffer,0,buffer.length);
for(int i =0; i < buffer.length; i++){
System.out.println(buffer[i]);
}
}
catch(Exception e){
System.out.println(e);
}
//finally
}
}
//int writer(char [] c,int off,int len)
import java.io.*;
publicclassTestChar{
publicstaticvoid main(String args []){
FileReader fr = null;
FileWriter fw = null;
try{
fr =newFileReader("D:/work/src/from.txt");
fw =newFileWriter("D:/work/src/to.txt");
char[] buffer =newchar[100];
int temp = fr.read(buffer,0,buffer.length);
fw.write(buffer,0,temp);
}
catch(Exception e){
System.out.println(e);
}
finally{
try{
fr.close();
fw.close();
}
catch(Exception e){
System.out.println(e);
}
}
}
}
标签:
原文地址:http://www.cnblogs.com/arroneve/p/5815460.html