Java中IO对象的输入输出流
2020-12-13 03:40
标签:int 输出流 txt java input stream tput throws dem 输入流: 输出流: Java中IO对象的输入输出流 标签:int 输出流 txt java input stream tput throws dem 原文地址:https://www.cnblogs.com/LixiaoFeng1650062546/p/11083529.htmlpublic void inputDemo () throws IOException {
//文件名称
String fileName = "d:\\aaa.txt";
//通过文件名称创建文件对象
File file = new File(fileName);
//创建一个输入流对象
// new FileOutputStream(file);
FileInputStream fis = new FileInputStream(fileName);
// int c;
// while ((c = fis.read()) > 0) {
// System.out.print((char)c);
// }
//创建一个字节数组
byte[] buf = new byte[2000];
int len;
//没有找到内容返回-1,所以判断有没内容。有则输出
while ((len = fis.read(buf)) > 0) {
System.out.println("新的一杯:");
System.out.println(new String(buf));
}
//关闭输入流
fis.close();
}public void outputDemo () throws IOException {
//创建输出对象流
FileOutputStream fos = new FileOutputStream("d:\\bbb.txt");
//通过输出创建写入流
OutputStreamWriter writer = new OutputStreamWriter(fos);
//通过写入流写入内容
writer.write("hello, output stream");
writer.close();
}
下一篇:PHP5安装oci8模块