IO流

来源:互联网 发布:js作用域链和原型链 编辑:程序博客网 时间:2024/06/06 16:39

**

IO流

**
字节IO流

       File file = new File("d://b.txt");       File file1=new File("d://a.txt");         if(!file.exists()){        try {            file.createNewFile();        } catch (IOException e) {            e.printStackTrace();        }       }        try {            FileInputStream fis=new FileInputStream(file1);            FileOutputStream fos=new FileOutputStream(file);            byte []array=new byte[1024];            int i=fis.read(array);            while(i!=-1){                fos.write(array, 0, i);                i=fis.read(array);            }            fis.close();            fos.flush();            fos.close();                } catch (FileNotFoundException e) {            e.printStackTrace();        } catch (IOException e) {            // TODO Auto-generated catch block            e.printStackTrace();        }    }

字节IO流字符IO流和缓冲流

    File file = new File("d://b.txt");    File file1=new File("d://a.txt");    if(!file.exists()){        try {            file.createNewFile();        } catch (IOException e) {            e.printStackTrace();        }    }        try {            FileInputStream fis=new FileInputStream(file1);            FileOutputStream fos=new FileOutputStream(file);            byte []array=new byte[1024];            int i=fis.read(array);            while(i!=-1){                fos.write(array, 0, i);                i=fis.read(array);            }            fis.close();            fos.flush();            fos.close();   //OutputStreamWriter osw=new OutputStreamWriter(fos);   //BufferedWriter  bw=new BufferedWriter(osw);   //String words="asdasdas";   // bw.write(words);   // bw.flush();   // bw.close();   // fos.close();   // osw.close();        } catch (FileNotFoundException e) {            e.printStackTrace();        } catch (IOException e) {            // TODO Auto-generated catch block            e.printStackTrace();        }    } // try { // FileInputStream fis = new  FileInputStream(file);// 这个读字节//InputStreamReader isr = new InputStreamReader(fis);// 这个读字符//BufferedReader br = new BufferedReader(isr);// 这个读行//String string = br.readLine(); //         while (string != null) {//              System.out.println(string);//              string = br.readLine();//          }//          fis.close();//          isr.close();//          br.close();//      } catch (FileNotFoundException e) {//          e.printStackTrace();//      } catch (IOException e) {//          e.printStackTrace();//      }    }
0 0
原创粉丝点击