Java io 流:常见的io类组合形式

java io流:几种常见的io类组合方式

try {

               DataOutputStream out =

                 new DataOutputStream(

                   new BufferedOutputStream(

                     new FileOutputStream("Data.txt")));

               out.writeDouble(3.14159);

               out.close();

 

               DataInputStream in =

                 new DataInputStream(

                   new BufferedInputStream(

                     new FileInputStream("Data.txt")));

               System.out.println(in.readDouble());

                in.close();

             } catch(Exception e) {

               System.out.println("fail");

                     }
------------------------------*--------------------------------------
 

byte[] buffer = new byte[255];

       try {

           BufferedOutputStream bos = new BufferedOutputStream(

                  new FileOutputStream(new File("file.txt")));

          

           BufferedInputStream bis = new BufferedInputStream(

                  new FileInputStream(new File("E:/Test/io/t.txt")));

           int length;

           length = bis.read(buffer);

           bis.close();

          

           bos.write(buffer,0,length);

           bos.close();

           }catch(EOFException e) {

                 System.out.println("fail");

            }

------------------------------*--------------------------------------

char[] buffer = new char[255];

       try{

           PrintWriter out

              = new PrintWriter(new BufferedWriter(new FileWriter("foo.txt")));

           

           BufferedReader in =

               new BufferedReader(

                 new FileReader("E:/Test/io/t.txt"));

             int length;

             length = in.read(buffer);

             System.out.println(length);

             in.close();

            

             out.write(buffer, 0, length);

             out.close();

       }

            catch(Exception e) {

                   System.out.println("fail");

}
------------------------------*--------------------------------------

char[] buffer = new char[255];

       try{

           PrintWriter out

              = new PrintWriter(new BufferedWriter(new FileWriter("foo.txt")));

          

             StringReader in = new StringReader("北京龙卷风科技");

             int length;

             length = in.read(buffer);

             in.close();

            

             out.write(buffer,0,length);

             out.close();

       }

        catch(Exception e) {

               System.out.println("fail");

             }    

你可能感兴趣的:(Java io 流:常见的io类组合形式)