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


        }
    }

  • 相关阅读:
    【学习笔记】查看CUDA版本
    如果Visual Studio太大,不妨还是用VSCode开发C#项目吧
    Visual Studio npm配置淘宝镜像
    c++读写锁--读者写者问题
    c++内存对象模型--vs2017下的分析,32位
    android作业
    android连接数据库
    android第十周(增删改查)
    android-购物车
    android计算器
  • 原文地址:https://www.cnblogs.com/hph1728390/p/10596540.html
Copyright © 2011-2022 走看看