java IO 流的学习(我们到底能走多远系列1)
2012-08-15 21:47
363 查看
我们到底能走多远系列(1)
“我们到底能走多远系列”:开始我的java之路。我要挖出这个地道,离开这里。IO入门代码阅读:
字节流:
private void writeTxt(String path, String value) throws IOException{ OutputStream fos = new FileOutputStream(path);//构造方法1 fos.write(value.getBytes()); fos.close(); } private void readTxt(String path) throws IOException{ File file = new File(path); InputStream fis = new FileInputStream(path);//构造方法2 byte b[] = new byte[(int)file.length()] ; fis.read(b); System.out.print(new String(b)); fis.close(); }
字符流:
private void writeTxt(String path, String value) throws IOException{ Writer writer = new FileWriter(path); writer.write(value); writer.close(); } private void readTxt(String path) throws IOException{ Reader reader = new FileReader(path); char c[] = new char[1024] ; int len = reader.read(c); System.out.print(new String(c, 0, len)); reader.close(); }
相关文章推荐
- 学习java中的几个Map-我们到底能走多远系列(27)
- How Tomcat Works 学习-我们到底能走多远系列(8)
- Java 阶段面试 知识点合集 - 我们到底能走多远系列(15)
- Sharded实现学习-我们到底能走多远系列(32)
- Tomcat StringManager阅读学习 -我们到底能走多远系列(10)
- 理解IO_InputStream-我们到底能走多远系列(16)
- java XML解析-我们到底能走多远系列(12)
- 关于ibatis批量问题-我们到底能走多远系列(26)
- 文件下载-excel导出-我们到底能走多远系列(22)
- ajax简单后台交互-我们到底能走多远系列(28)
- java NIO-我们到底能走多远系列(39)
- Java NIO基础 -我们到底能走多远系列(17)
- JAVA IO源码学习系列一(ByteArrayOutputStream)
- JMS生产者+单线程发送-我们到底能走多远系列(29)
- InternalInputBuffer处理HTTP请求行-Tomcat源码-我们到底能走多远系列(11)
- js中this和回调方法循环-我们到底能走多远系列(35)
- 利用spring AOP 和注解实现方法中查cache-我们到底能走多远系列(46)
- cglib源码主流程源码-我们到底能走多远系列48
- JAVA IO源码学习系列之InputStream