- 博客(0)
- 资源 (1)
空空如也
java io InputStream and outputStream
适合初学者的一些代码,public static void main(String[] args) {
File file1 = new File("c:\\aaa.txt");// 定位文件
if (!file1.exists()) {
System.out.println("文件不存在....");
} else {
try {
InputStream is = new FileInputStream(file1);// 打开文件
byte[] cont = new byte[(int) file1.length()];
is.read(cont);// 读取文件
for (int i = 0; i < cont.length; i++) {
System.out.print((char) cont[i]);
}
is.close();// 关闭文件
// 保存文件
File file2 = new File("bbb.txt");// 定位文件
OutputStream os = new FileOutputStream(file2);// 打开文件
os.write(cont);
os.close();// 关闭文件
} catch (FileNotFoundException e) {
e.printStackTrace();
} catch (IOException e) {
e.printStackTrace();
}
}
}
2013-07-04
空空如也
TA创建的收藏夹 TA关注的收藏夹
TA关注的人