V2EX = way to explore
V2EX 是一个关于分享和探索的地方
Sign Up Now
For Existing Member  Sign In
fangch
V2EX  ›  问与答

Java 项目部署 Linux 上为啥读取不到中文目录

  •  1
     
  •   fangch · Jul 5, 2022 · 831 views
    This topic created in 1397 days ago, the information mentioned may be changed or developed.

    需求:
    读取 linux 项目上的文件结构显示出来
    问题:
    java 项目部署在 linux 平台上,读取 linux 上的文件目录,但是当遇到中文目录的时候,就无法读取到了,英文的可以,这个是什么原因?
    我搜了很多,都说是编码问题,但是转了编码,貌似还是不行?搞了大半天都不行,各位大佬帮帮忙
    代码如下

    String sysRunPath = GCONST.getRootPath();
    String filePath = sysRunPath + "ClifePage" + File.separatorChar + "train" + File.separatorChar + "OATrainingCourse";//读取父目录
    // File file = new File( new String(filePath.getBytes("gbk"), "utf-8")); 转码了但是还是有问题
    File file = new File(filePath);
    JSONArray ja = new JSONArray();
    JSONArray jc = new JSONArray();
    try {
    showFile(file, ja);//列出父目录下面的子目录
    jc = ja.getJSONObject(0).getJSONArray("children");
    } catch (JSONException e) {
    e.printStackTrace();
    }

    No Comments Yet
    About   ·   Help   ·   Advertise   ·   Blog   ·   API   ·   FAQ   ·   Solana   ·   960 Online   Highest 6679   ·     Select Language
    创意工作者们的社区
    World is powered by solitude
    VERSION: 3.9.8.5 · 31ms · UTC 23:36 · PVG 07:36 · LAX 16:36 · JFK 19:36
    ♥ Do have faith in what you're doing.