• java工程生成jar,配置文件放在jar外面,读写配置文件


    public class Resource {
        public static void main(String[] args) {
            writeFile("562");
            readFileByChars();
        }
    
        public static void writeFile(String news_id) {
            FileOutputStream fsOut = null;
            String filePath = System.getProperty("user.dir")
                    + "/conf/newsid.txt";
            try {
                fsOut = new FileOutputStream(filePath);
                byte[] b1 = news_id.getBytes();
                fsOut.write(b1);
                fsOut.close();
                System.out.println(news_id+"写入CT成功!");
            } catch (Exception e) {
                e.printStackTrace();
            } finally {
                try {
                    fsOut.close();
                } catch (IOException e) {
                    e.printStackTrace();
                }
            }
    
        }
    
        public static String readFileByChars() {
            String weixinid = "";
            String filePath = System.getProperty("user.dir")
                    + "/conf/newsid.txt";
            Reader reader = null;
            try {
                reader = new InputStreamReader(new FileInputStream(filePath));
                int tempchar;
                while ((tempchar = reader.read()) != -1) {
                    if (((char) tempchar) != '
    ') {
                        // System.out.print((char) tempchar);
                        weixinid += (char) tempchar + "";
                    }
                }
                reader.close();
            } catch (Exception e) {
                e.printStackTrace();
            } finally {
                try {
                    reader.close();
                } catch (IOException e1) {
                    e1.printStackTrace();
                }
            }
            return weixinid;
        }
    }


  • 相关阅读:
    T3java核心API基础类
    java字符编码
    Servlet 1
    T2java面向对象
    T1java语言基础
    Mac OS mysql数据库安装与初始化
    java多线程中注入Spring对象问题
    T4java核心API集合类
    The first day Teddy
    Spring第二节 注入依赖
  • 原文地址:https://www.cnblogs.com/hzcya1995/p/13317841.html
Copyright © 2020-2023  润新知