zoukankan      html  css  js  c++  java
  • 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);
     }

    }

  • 相关阅读:
    SpringBoot启动类踩坑
    数组作业
    多态的使用
    intellij idea怎么设置软件启动时选择项目进入
    方法的递归调用
    取一个数字数字后4位的和
    day09作业
    java 随机数
    java 方法
    java 循环作业
  • 原文地址:https://www.cnblogs.com/fengke/p/4916088.html
Copyright © 2011-2022 走看看