字節轉換成字符



  import java.io.*;
    public class Outchant {


//        字節轉化成字符類型
 
    public static void main(String[] args) {

  //    異常處理
            try {
                  fun();
                  fun1();
            }    catch (Exception e) {
            
                e.printStackTrace();
        }
    }
    

 


//    字節轉化成字符類型

 


       public static void  fun() throws Exception{

 


//         創建要在那個文件中續寫文字

  
            FileOutputStream fos=new FileOutputStream("d:\\IO\\ac.txt",true);


//        寫的格式為utf-8

           OutputStreamWriter fow=new OutputStreamWriter(fos,"utf-8");


//                    續寫的文字


              fow.write("學的還行");
        
                fow.close();
    }

      public static void fun1() throws Exception{


//            讀取文件中的文字


            FileInputStream fis=new FileInputStream("d:\\IO\\ac.txt");


//              速度為1M


            byte [] b=new byte[1024*10] ;


//              定義長度為0;


            int len=0;


//            如果長度為-1結束運行


            while((len=fis.read(b))!=-1){


//                  打印


                System.out.println(new String(b,0,len));
        }


              fis.close();


    }
}


免責聲明!

本站轉載的文章為個人學習借鑒使用,本站對版權不負任何法律責任。如果侵犯了您的隱私權益,請聯系本站郵箱yoyou2525@163.com刪除。



 
粵ICP備18138465號   © 2018-2025 CODEPRJ.COM