zoukankan      html  css  js  c++  java
  • I/O-<文件读写、输出>

    读写

    FileInputStream fis=null;
    fis=new FileInputStream("D://2016.txt");//初始文件位置
    int i=0;
    byte[] bArray=new byte[1024];//通过比特类型来实现汉字的输入
    sb=new StringBuffer();
    while((i=fis.read(bArray))!=-1){  //从fis将内容读入bArray数组里面
        // char ch=(char) i;
        //sb.append(ch);
         sb.append(new String(bArray));//输出
    }
    System.out.println(sb.toString()); */

     写出文件(等同于复制)

    fis=new FileInputStream("D://2016.txt");
    fos=new FileOutputStream("E://2016.txt");
    int i=0;
    while((i=fis.read())!=-1){
    	fos.write(i);   //写出文件
    }

      注意:两种都得添加try{}catch{}异常处理(文件不存在的问题),最后关闭fis和fos

  • 相关阅读:
    HDU 5444 Elven Postman 二叉排序树
    HDU 5438 Ponds dfs模拟
    Gym
    markdown test
    Gym
    集训回顾
    UVALive
    UVALive
    UVALive
    codeforcres 589 J
  • 原文地址:https://www.cnblogs.com/bpdxqx/p/5772317.html
Copyright © 2011-2022 走看看