您的位置:首页 > 其它

IO流

2015-08-02 22:08 232 查看
**

IO流

**

字节IO流

File file = new File("d://b.txt");
File file1=new File("d://a.txt");
if(!file.exists()){
try {
file.createNewFile();
} catch (IOException e) {
e.printStackTrace();
}
}
try {
FileInputStream fis=new FileInputStream(file1);
FileOutputStream fos=new FileOutputStream(file);
byte []array=new byte[1024];
int i=fis.read(array);
while(i!=-1){
fos.write(array, 0, i);
i=fis.read(array);
}

fis.close();
fos.flush();
fos.close();
} catch (FileNotFoundException e) {
e.printStackTrace();
} catch (IOException e) {
// TODO Auto-generated catch block
e.printStackTrace();
}

}


字节IO流字符IO流和缓冲流

File file = new File("d://b.txt");
File file1=new File("d://a.txt");
if(!file.exists()){
try {
file.createNewFile();
} catch (IOException e) {
e.printStackTrace();
}
}
try {
FileInputStream fis=new FileInputStream(file1);
FileOutputStream fos=new FileOutputStream(file);
byte []array=new byte[1024];
int i=fis.read(array);
while(i!=-1){
fos.write(array, 0, i);
i=fis.read(array);
}

fis.close();
fos.flush();
fos.close();
//OutputStreamWriter osw=new OutputStreamWriter(fos);
//BufferedWriter  bw=new BufferedWriter(osw);
//String words="asdasdas";
// bw.write(words);
// bw.flush();
// bw.close();
// fos.close();
// osw.close();
} catch (FileNotFoundException e) {
e.printStackTrace();
} catch (IOException e) {
// TODO Auto-generated catch block
e.printStackTrace();
}

}
// try {
// FileInputStream fis = new  FileInputStream(file);// 这个读字节
//InputStreamReader isr = new InputStreamReader(fis);// 这个读字符
//BufferedReader br = new BufferedReader(isr);// 这个读行
//String string = br.readLine();
//         while (string != null) {
//              System.out.println(string);
//              string = br.readLine();
//          }
//          fis.close();
//          isr.close();
//          br.close();
//      } catch (FileNotFoundException e) {
//          e.printStackTrace();
//      } catch (IOException e) {
//          e.printStackTrace();
//      }

}
内容来自用户分享和网络整理,不保证内容的准确性,如有侵权内容,可联系管理员处理 点击这里给我发消息
标签: