V2EX = way to explore
V2EX 是一个关于分享和探索的地方
现在注册
已注册用户请  登录
V2EX 提问指南
fangch
V2EX  ›  问与答

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

  •  1
     
  •   fangch · 2022-07-05 19:02:17 +08:00 · 560 次点击
    这是一个创建于 672 天前的主题,其中的信息可能已经有所发展或是发生改变。

    需求:
    读取 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();
    }

    目前尚无回复
    关于   ·   帮助文档   ·   博客   ·   API   ·   FAQ   ·   我们的愿景   ·   实用小工具   ·   1026 人在线   最高记录 6543   ·     Select Language
    创意工作者们的社区
    World is powered by solitude
    VERSION: 3.9.8.5 · 26ms · UTC 21:58 · PVG 05:58 · LAX 14:58 · JFK 17:58
    Developed with CodeLauncher
    ♥ Do have faith in what you're doing.