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


        }
    }

  • 相关阅读:
    eslint and stylelint config
    CSS3 animaion 和 transition 比较
    css之px、em、rem
    Three.js 中 相机的常用参数含义
    ES6中函数调用自身需要注意的问题
    MySQL数据库迁移之data目录
    ES6扩展运算符(三点运算符)...的用法
    Vue 组件通信方案
    关于ES6中Promise的应用-顺序合并Promise,并将返回结果以数组的形式输出
    Ubuntu 使用gps
  • 原文地址:https://www.cnblogs.com/hph1728390/p/10596540.html
Copyright © 2011-2022 走看看