【文件属性】:
文件名称:java io InputStream and outputStream
文件大小:3KB
文件格式:RAR
更新时间:2016-07-24 09:56:54
java io
适合初学者的一些代码,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();
}
}
}
【文件预览】:
04_java_io
----.project(386B)
----bin()
--------com()
----bbb.txt(21B)
----src()
--------com()
----aaa.txt(31B)
----.classpath(232B)
网友评论
- 适合初学者的一些代码
- 挺好的,我正用得上!