JDK1.5 での開発を行わなくてはならないこと。あまり開発作業環境が統一&整備されていない状況。
そんな中で日本語文字を含むプロパティの必要性が発生してしまった場合は困る。
JDK1.6 なら、ResouceBundle.Controle が存在して newBundle をオーバライドして対処できるのに。。。
しかたなく、以下を用意した。
import java.io.BufferedReader;
import java.io.File;
import java.io.FileInputStream;
import java.io.IOException;
import java.io.InputStreamReader;
import java.util.Properties;
/**
* properties read
*/
public final class PropertyUtil{
private PropertyUtil(){}
public static Properties read(String path) throws IOException{
return read(new File(path));
}
public static Properties read(File file) throws IOException{
return read(file,"UTF-8");
}
public static Properties read(String path,String encode) throws IOException{
return read(new File(path),encode);
}
public static Properties read(File file,String encode) throws IOException{
Properties prop = new Properties();
BufferedReader br = new BufferedReader(new InputStreamReader(
new FileInputStream(file)
,encode
));
String line;
while*1 != null){
int eq = line.indexOf("=");
if (eq <= 0) continue;
if (line.startsWith("#")) continue;
prop.put(
line.substring(0,eq).trim()
,line.substring(eq+1).trim()
);
}
br.close();
return prop;
}
}