zoukankan      html  css  js  c++  java
  • 字节转换成字符


      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();


        }
    }

  • 相关阅读:
    Redis实战(十)Redis常见问题及解决方案
    小团队构建大网站:中小研发团队架构实践
    Asp.net core 3.0
    图解TCP/IP
    TCP/IP协议
    Grid画边框
    WPF常用方法,事件驱动和控件遍历
    WPF中的画图
    WPF中的常用类汇总:
    WPF中的VisualTreeHelper
  • 原文地址:https://www.cnblogs.com/hph1728390/p/10596540.html
Copyright © 2011-2022 走看看