避免 utf can tle == 文件的 coder txt col
- package com.cn.test;
- import java.io.File;
- import java.io.FileInputStream;
- import java.io.IOException;
- import java.net.URLDecoder;
- import java.util.Properties;
- import java.util.Scanner;
- public class FileTest {
- public static void main(String[] args) throws IOException {
- Properties prop = new Properties();
- String path = null;
- System.out.println(new File("").getCanonicalPath() + "\\setting.txt");
- // String path = Thread.currentThread().getContextClassLoader().getResource("setting.txt").getPath();
- if (path == null) {
- path = "./setting.txt";
- }
- FileInputStream in =null;
- while (true) {
- Scanner sc = new Scanner(System. in );
- String s = sc.next();
- char c = s.charAt(0);
- if (c == ‘0‘) {
- break;
- }
- try {
- path = URLDecoder.decode(path, "UTF-8"); in =new FileInputStream(path);
- prop.load( in );
- prop.list(System.out);
- } catch(Exception e) {
- e.printStackTrace();
- } finally {
- try {
- if ( in !=null) { in .close();
- }
- } catch(IOException e) {
- e.printStackTrace();
- }
- }
- }
- }
- }
- A = 2323333dsfds
避免缓存,Java动态加载配置文件
来源: http://www.bubuko.com/infodetail-2323225.html