- 2
- 0
- 约1.14万字
- 约 54页
- 2016-06-01 发布于湖北
- 举报
public static void main(String[] args) throws Exception { OutputStream out = new FileOutputStream(test.txt); out.write(hello.getBytes()); out.flush(); out.close(); } public static void main(String[] args) throws Exception { OutputStream out = new FileOutputStream(test.txt,true); byte[] bys = hello.getBytes(); for (int i = 0; i bys.length; i++) { out.write(bys[i]);//每次只写入一个内容 } out.flush(); out.close(); } OutputStreamTest.java int available() throws IOException:文件大小 abstract void close() throws IOException:关闭流 int read() throws IOException:从输入流中读取单个字节。 int read(byte[] b) throws IOException:从输入流中读取最多b.length个字节的数据,并将其存储在字节数组b中,返回实际读取的字节。 直到read(byte[] b)函数返回-1表示输入流的结束。 以其子类FileInputStream来实例化InputStream对象 FileInputStream(File/String file) throws FileNotFoundException 创建一个向指定 File 对象表示的文件中写入数据的文件输出流。 public static void main(String[] args) { String path = pathName; InputStream input = null; input = new FileInputStream(new File(path)); // 定义缓冲区 byte[] bys = new byte[50]; int len = 0; while ((len = input.read(bys)) != -1) { System.out.println(new String(bys, 0, len)); } input.close(); } } InputStreamTest.java 1个字符 等于 2个字节 字符流主要是操作char的类型数据: 字符输出流:Writer 字符输入流:Readr abstract void close() throws IOException:关闭流 int read() throws IOException:从输入流中读取单个字符。 int read(char[] cbuf) throws IOException:从输入流中读取最多c.length个字节的数据,并将其存储在字符数组c中,返回实际读取的字节。 直到read(char[] c)函数返回-1表示输入流的结束。 char[] cBuff = new char[1024];//动态声明数组,长度 read(cBuff ) !=-1 read(cBuff ) 0 以其子类FileReader来实例化Reader对象 FileReader(File/String file) throws FileNotFoundException 创建一个向指定对象的文件输入流 public static void main(String[] args) { String path = pathName; Reader reader = null; reader = new FileReader(new File(path)); // 定义缓冲区 char[] buf = new char[50]; int len = 0; // 循环读取直到为空的时候 while ((len = reader.read(buf)) != -1) { System.out.println(new String(buf, 0, len)); } reader.close(); } } abstract void flush() throws IOException:清空缓存 abstr
您可能关注的文档
- 基于集团战略导向的管控模式分析.ppt
- 机械制造技术基础绪论分析.ppt
- 基于绩效的企业培训体系演示版天new分析.ppt
- 机械制造技术基础张世昌第1章机械制造技术分析.ppt
- 基于绩效的薪酬体系设计分析.ppt
- 基于交互电子白板的教学设计案例分析.ppt
- 基于交互式子电白板的课堂教学设计分析.ppt
- 基于教科研发展趋势的论文写作策略分析.ppt
- 机械制造技术课程设计集中辅导().分析.ppt
- 机械制造课程设计分析.ppt
- 2025-2026学年天津市和平区高三(上)期末数学试卷(含解析).pdf
- 2025-2026学年云南省楚雄州高三(上)期末数学试卷(含答案).pdf
- 2025-2026学年甘肃省天水市张家川实验中学高三(上)期末数学试卷(含答案).docx
- 2025-2026学年福建省厦门市松柏中学高二(上)期末数学试卷(含答案).docx
- 2025-2026学年广西钦州市高一(上)期末物理试卷(含答案).docx
- 2025-2026学年河北省邯郸市临漳县九年级(上)期末化学试卷(含答案).docx
- 2025-2026学年河北省石家庄二十三中七年级(上)期末历史试卷(含答案).docx
- 2025-2026学年海南省五指山市九年级(上)期末化学试卷(含答案).docx
- 2025-2026学年河北省唐山市玉田县九年级(上)期末化学试卷(含答案).docx
- 2025-2026学年河北省邢台市市区九年级(上)期末化学试卷(含答案).docx
原创力文档

文档评论(0)