码迷,mamicode.com
首页 > 编程语言 > 详细

JAVA IO流小实例

时间:2017-05-05 18:28:07      阅读:145      评论:0      收藏:0      [点我收藏+]

标签:stream   input   buffer   sys   put   static   iter   stat   fileinput   

package demo;

import java.io.BufferedReader;
import java.io.BufferedWriter;
import java.io.File;
import java.io.FileInputStream;
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 Demo04{

public static void main(String[] args) throws IOException{

File fw = new File("E:\\tt.txt");
File fr = new File("F:\\PB学习\\pb.txt");
Demo04.FileWriter(fr, fw);
}

public static void FileWriter(File in,File ot) throws IOException{

if(!in.exists()){
in.getParentFile().mkdirs();
in.createNewFile();
}
if(!ot.exists()){
ot.getParentFile().mkdirs();
ot.createNewFile();
}

InputStreamReader isr=new InputStreamReader(new FileInputStream(in));
OutputStreamWriter osw=new OutputStreamWriter(new FileOutputStream(ot),"utf-8");

BufferedReader br = new BufferedReader(isr);
BufferedWriter bw = new BufferedWriter(osw);

char[] buffer = new char[1024];
int c;
while ((c = br.read(buffer,0,1024)) != -1) {
bw.write(buffer,0,c);
}
br.close();
bw.close();
System.out.println("OK");
}

}

JAVA IO流小实例

标签:stream   input   buffer   sys   put   static   iter   stat   fileinput   

原文地址:http://www.cnblogs.com/wumianjing/p/6814105.html

(0)
(0)
   
举报
评论 一句话评论(0
登录后才能评论!
© 2014 mamicode.com 版权所有  联系我们:gaon5@hotmail.com
迷上了代码!