• RandomAccessFile乱码问题


    package fengke.filedemo;

    import java.io.File;
    import java.io.FileNotFoundException;
    import java.io.IOException;
    import java.io.RandomAccessFile;
    /**
     * RandomAccessFileDemoChina乱码问题
     * @author 锋客
     * 内容:
     *    String s=new String(raf_open.readLine().getBytes("ISO-8859-1"),"utf-8");
     */

    public class RandomAccessFileDemoChina {

     public static void main(String[] args) throws IOException {
      //写入
      File file=new File("e:\luanma.txt");
      file.createNewFile();
      try {
       RandomAccessFile raf=new RandomAccessFile(file, "rw");
       raf.writeUTF("晋城,锋客到此一游!");
       raf.close();
      } catch (FileNotFoundException e) {
       // TODO Auto-generated catch block
       e.printStackTrace();
      }
      //输出
      RandomAccessFile raf_open=new RandomAccessFile(file, "r");
      System.out.println("乱码:"+raf_open.readLine());
      raf_open.seek(0);//必须规到0处
      //readLine的方式会自动将编码变成ISO-8859-1,后一个是自己的文本编码格式
      String s=new String(raf_open.readLine().getBytes("ISO-8859-1"),"utf-8");
      System.out.println(s);
     }

    }

  • 相关阅读:
    python 字符串内建函数之开头与结尾判断
    python 字符串内建函数之查找、替换
    python 字符串内建函数之大小写
    python 字符串切片
    python for循环
    python if语句
    python input( )
    python 变量命名规则
    DllMain
    静态库lib和动态dll的区别及使用方法
  • 原文地址:https://www.cnblogs.com/fengke/p/4916088.html
Copyright © 2020-2023  润新知