zoukankan      html  css  js  c++  java
  • ideal中项目resources下txt文件读取不到的问题。

      这次做项目,原来用到了一个txt文件,在ideal中项目启动后报读取不到txt文件。项目原来是在eclipse中的。

      在网上找了些文章,发现ideal中要读取到resources下的文件需要加上下面红色标注部分的一个方法。。

     /**
         * 汉字数据文件
         */
        private static final String HAN_DATA_FILE = "chinesedata.txt";
    private static void loadHanData() throws IOException {
            System.out.println("Loading data ...");
            URL u = BBCFChineseDict.class.getResource(HAN_DATA_FILE);
            System.out.println(u);
    
            InputStream in = BBCFChineseDict.class.getClassLoader().getResourceAsStream(HAN_DATA_FILE);
    
            if (in == null) {
                throw new IOException(HAN_DATA_FILE + "汉字数据文件不存在!");
            }
    
            try {
                BufferedReader br = new BufferedReader(new InputStreamReader(in, FILE_CHARSET));
                String line = null;
                int index = 0;
                while ((line = br.readLine()) != null) {
                    HAN_DATA[index++] = line;
                }
            } finally {
                if (in != null) {
                    in.close();
                }
            }
        }

    参考文章:https://blog.csdn.net/guo_guo_cai/article/details/79866692

  • 相关阅读:
    函数
    registry搭建及镜像管理-harbor
    用户输入和while 循环
    dockerfile
    字典,set
    if 语句
    alpine操作
    循环:列表,元组
    列表
    docker跨主机通信-overlay
  • 原文地址:https://www.cnblogs.com/prader6/p/10309270.html
Copyright © 2011-2022 走看看