java中缓冲读写buffer基础程序
来源:互联网 发布:mac好用的office软件 编辑:程序博客网 时间:2024/05/18 18:19
package com.buffered;
import java.io.*;
public class TestBufferedIO {
public static void main(String[] args) {
String path = "d:/SQLHelp.java";
TestBufferedIO t = new TestBufferedIO();
try {
// t.read2(path);
//t.read3();
//PrintStream ps = System.out;
PrintStream ps = new PrintStream(new File("d:/SQLHelp1.java")); t.list(path, ps);
} catch (IOException e) {
e.printStackTrace();
}
}
/**
* 测试字节流的处理流 * * @param path * @throws IOException */ public void read1(String path) throws IOException { File f = new File(path); InputStream is = new FileInputStream(f); BufferedInputStream bis = new BufferedInputStream(is); byte[] bs = new byte[20]; int flag = -1; while ((flag = bis.read(bs)) != -1) { String msg = new String(bs); System.out.print(msg); } bis.close(); is.close(); } /** * 测试打印流 * * @param f * @param fs
public static void list(String f, PrintStream fs) throws IOException { try { BufferedReader br = new BufferedReader(new FileReader(f)); String s = null; while ((s = br.readLine()) != null) { fs.println(s); } br.close(); } catch (IOException e) { } } fs.println("无法读取文件"); /** * 测试字符流的处理流 * * @param path * @throws IOException */ public void read2(String path) throws IOException { File f = new File(path); Reader reader = new FileReader(f); BufferedReader br = new BufferedReader(reader); String msg = null; while ((msg = br.readLine()) != null) { System.out.println(msg); } br.close(); reader.close(); } /** * 接收键盘输入 */ public void read3() throws IOException { System.out.println("用户请输入内容:"); InputStream is = System.in; BufferedReader reader = new BufferedReader(new InputStreamReader(is)); String msg = null; while ((msg = reader.readLine()) != null) { System.out.println(msg); } reader.close();
} }
public static void list(String f, PrintStream fs) throws IOException { try { BufferedReader br = new BufferedReader(new FileReader(f)); String s = null; while ((s = br.readLine()) != null) { fs.println(s); } br.close(); } catch (IOException e) { } } fs.println("无法读取文件"); /** * 测试字符流的处理流 * * @param path * @throws IOException */ public void read2(String path) throws IOException { File f = new File(path); Reader reader = new FileReader(f); BufferedReader br = new BufferedReader(reader); String msg = null; while ((msg = br.readLine()) != null) { System.out.println(msg); } br.close(); reader.close(); } /** * 接收键盘输入 */ public void read3() throws IOException { System.out.println("用户请输入内容:"); InputStream is = System.in; BufferedReader reader = new BufferedReader(new InputStreamReader(is)); String msg = null; while ((msg = reader.readLine()) != null) { System.out.println(msg); } reader.close();
} }
- java中缓冲读写buffer基础程序
- Ring buffer basics 环形缓冲基础 一
- JAVA基础:使用缓冲IO提高Java程序性能
- Java优化组件缓冲(Buffer)
- java文件读写(buffer)
- 【设计优化】-使用缓冲(Buffer)提高程序性能
- java中双缓冲
- 利用Java读写锁设计缓冲类
- Java NIO - Buffer 基础 -1
- java.nio.Buffer缓冲区基础
- 缓冲(Buffer)解释
- 缓冲设计-buffer
- 帧缓冲 Frame Buffer
- Netty Buffer(缓冲)
- Java中nio与buffer
- Java中使用Protocol Buffer
- Java中 Buffer的作用
- Java基础 文件读写
- Hadoop学习路线图
- oracle 11g 锁处理
- Denosing Autoencoder训练过程代码详解
- 如何制作可以直接带来销售转化的着陆页
- UE4加载播放网络上的视频
- java中缓冲读写buffer基础程序
- 爬取糗事百科的spider
- HTML练习---加盟申请表
- ScrollView嵌套ListView的问题
- Linux vi常用命令大全
- 官方文档才是王道:PonyDebugger安装坑的感悟;
- 每天一个算法练习之字符空格替换
- Web负载均衡的几种实现方式
- 10 Python 函数内使用全局变量注意项