package demo14;
import java.io.BufferedReader;
import java.io.BufferedWriter;
import java.io.File;
import java.io.FileWriter;
import java.io.IOException;
import java.io.InputStreamReader;
import javax.annotation.processing.Filer;
import javax.lang.model.element.Element;
import javax.tools.FileObject;
import javax.tools.JavaFileObject;
import javax.tools.JavaFileManager.Location;
public class Demo01 {
public static void main(String[] args) {
BufferedReader br = null;
BufferedWriter bw = null;
br=new BufferedReader(new InputStreamReader(System.in));//字节流的读取向字符流
try {
bw=new BufferedWriter(new FileWriter(new File("d:tianmimi.txt")));
String temp=null;
while ((temp=br.readLine())!=null) {
if (temp.equals("quit")) {
break;
}
bw.write(temp);
bw.newLine();
}
bw.flush();
} catch (IOException e) {
// TODO 自动生成的 catch 块
e.printStackTrace();
}
}
}
package demo14;
import java.io.File;
import java.io.FileInputStream;
import java.io.FileNotFoundException;
import java.io.FileOutputStream;
import java.io.IOException;
public class InputStreamDemo {
public static void main(String[] args) {
FileInputStream fis=null ;//读取
FileOutputStream fos=null;//写入
try {
fis=new FileInputStream(new File("d:\\coolgirl.jpg"));
fos=new FileOutputStream(new File("d:\\woaini.jpg"));
byte[] b =new byte[1024];
int length=0;
try {
while ((length=fis.read(b))!=-1) {
fos.write(b,0,length);
}
} catch (IOException e) {
// TODO 自动生成的 catch 块
e.printStackTrace();
}
}
catch (FileNotFoundException e) {
// TODO 自动生成的 catch 块
e.printStackTrace();
}
finally {
try {
fis.close();
fos.close();
} catch (Exception e2) {
// TODO: handle exception
}
}
}
}