实训的第七天 加油

来源:互联网 发布:ipad换壁纸软件 编辑:程序博客网 时间:2024/06/06 03:03
io流
output   input 
写输出   读输入
字节流:outputStream(内存——文件),inputStream(文件——内存)(直接进行操作)
字符流:Read,Write(先缓存在操作)

对内容按行读用字符流

 

简单的输入流

package com.lenvov.io;import java.io.*;public class InputOutput {public static void main(String[] args) {// TODO Auto-generated method stubtry {FileInputStream input=new FileInputStream("d:/lenovo/hello.txt");FileOutputStream output=new FileOutputStream("d:/lenovo/study/log.txt");int n=input.read();while(n>-1){output.write(n);n=input.read();}input.close();output.close();} catch (FileNotFoundException e) {// TODO Auto-generated catch blocke.printStackTrace();} catch (IOException e) {// TODO Auto-generated catch blocke.printStackTrace();}}}

简单的输出流

package com.lenvov.io;import java.io.FileNotFoundException;import java.io.FileOutputStream;import java.io.IOException;public class NewOutputStream {public static void main(String[] args){// TODO Auto-generated method stubtry {FileOutputStream out=new FileOutputStream("d:/lenovo/hello.txt");String s="1213";out.write(s.getBytes());out.close();} catch (FileNotFoundException e) {// TODO Auto-generated catch blocke.printStackTrace();} catch (IOException e) {// TODO Auto-generated catch blocke.printStackTrace();}}}



原创粉丝点击