标签:
public void Input() throws IOException{
FileInputStream fis=new FileInputStream("D:\\22\\myDoc\\space.txt");
byte[] b=new byte[fis.available()];
while((fis.read(b))!=-1){
System.out.println(new String(b));
}
fis.close();
}
public void Output() throws IOException{
FileOutputStream fos=new FileOutputStream("D:\\22\\myDoc\\space.txt");
File file=new File("D:\\22\\myDoc\\space.txt");
if(!file.exists()){
file.mkdir();
System.out.println("创建成功!");
}
String string="hahahhahaha";
fos.write(string.getBytes());
fos.flush();
fos.close();
}
public void Writer() throws IOException{
FileOutputStream fos=null;//字节流
OutputStreamWriter osw=null;//字节转字符流
BufferedWriter bw=null;//字符流
fos=new FileOutputStream("D:\\text\\text.txt");
osw=new OutputStreamWriter(fos);
bw=new BufferedWriter(osw);
bw.write("无敌是多么寂寞!");
bw.flush();
osw.flush();
fos.flush();
bw.close();
osw.close();
fos.close();
}
public void Reader() throws IOException{
FileInputStream fis=null;
InputStreamReader isw=null;
BufferedReader br=null;
fis=new FileInputStream("D:\\text\\text.txt");
isw=new InputStreamReader(fis);
br=new BufferedReader(isw);
String cstring="";
while((cstring=br.readLine())!=null){
System.out.println(c);
}
br.close();
isw.close();
fis.close();
}
标签:
原文地址:http://www.cnblogs.com/BLJworld1994/p/5787173.html