IO流
来源:互联网 发布:网络攻击防御体系 编辑:程序博客网 时间:2024/06/03 23:34
IO流*
output input
写输出 读输入
字节流:outputStream(内存——文件)
package com.lenovo.file;import java.io.File;import java.io.FileNotFoundException;import java.io.FileOutputStream;public class LenovoDeom3 { public static void main(String[] args) { File file=new File("E:/java/12.txt"); try { FileOutputStream out=new FileOutputStream(file); out.close(); } catch (FileNotFoundException e) { // TODO Auto-generated catch block e.printStackTrace(); } }}
,inputStream(文件——内存)(直接进行操作)
package com.lenovo.file;import java.io.File;import java.io.FileInputStream;import java.io.FileNotFoundException;import java.io.IOException;import java.io.InputStream;public class LenovoDeom3 { public static void main(String[] args) { File file=new File("E:/java/12.txt"); try { FileInputStream input=new FileInputStream(file); int len=input.read(); while(len!=-1){ System.out.print((char)len); len=input.read(); } } catch (FileNotFoundException e) { // TODO Auto-generated catch block e.printStackTrace(); } catch (IOException e) { // TODO Auto-generated catch block e.printStackTrace(); } }}
字符流:Read
package com.lenovo.file;import java.io.File;import java.io.FileReader;import java.io.IOException;public class D { public static void main(String[] args) { // TODO Auto-generated method stub File file=new File("e:/java/12.txt"); try { FileReader w=new FileReader(file); char[] c=new char[1024]; int len=w.read(c); System.out.println(new String(c,0,len)); } catch (IOException e) { // TODO Auto-generated catch block e.printStackTrace(); } }}
Write(先缓存在操作)
package com.lenovo.file;import java.io.File;import java.io.FileWriter;import java.io.IOException;public class D { public static void main(String[] args) { // TODO Auto-generated method stub File file=new File("e:/java/12.txt"); try { FileWriter w=new FileWriter(file); String s="java"; w.write(s); w.close(); } catch (IOException e) { // TODO Auto-generated catch block e.printStackTrace(); } }}
对内容按行读用字符流
阅读全文
0 0
- 【IO流】IO框架
- IO流呀IO流
- 字符IO&数据流IO&对象流IO
- io流
- io流
- IO流
- IO流
- IO 流
- IO流
- io流
- IO流
- io流
- IO流
- IO流
- IO流
- IO流
- IO流
- IO流
- 双向链表的实现
- BZOJ3687:简单题
- 48-C语言-子串
- reactNative官方文档重难点摘录
- /usr/bin/ld: cannot find -lm的解决方法
- IO流
- eclipse中碰到的异常
- Hadoop环境搭建(ubuntu+hadoop2.7
- Linux系统操作(3)———JDK、eclipse、Tomcat的安装
- 1118. Birds in Forest (25)[并查集]
- ViewFlipper
- (DP)LeetCode#53. Maximum Subarray
- 浏览器中调试js代码
- c++实现简单eval