質問編集履歴
1
皆さんの回答のpropertiesファイルを作ってやってみました
title
CHANGED
File without changes
|
body
CHANGED
@@ -54,4 +54,62 @@
|
|
54
54
|
|
55
55
|
今はandroidアプリが作りたくてjavaを勉強してます
|
56
56
|
android studioにはエディタで弄れるローカライズ方法が備わっていると聞いたのですが
|
57
|
-
javaではどうするのだろうと気になったので質問しました
|
57
|
+
javaではどうするのだろうと気になったので質問しました
|
58
|
+
|
59
|
+
|
60
|
+
>>>>>>>>
|
61
|
+
みなさんの言っていたPropertiesで書いてみました
|
62
|
+
try分の例外の書き方がわからなかったのでテキトウですがなんとか表示されました
|
63
|
+
あと文字化けに苦労しましたがnative2asciiで出来ました
|
64
|
+
自分の参考にコードを載せときます
|
65
|
+
|
66
|
+
jp.properties
|
67
|
+
```
|
68
|
+
asa=おはよう
|
69
|
+
hiru=こんにちは
|
70
|
+
ban=さよなら
|
71
|
+
```
|
72
|
+
|
73
|
+
en.properties
|
74
|
+
```
|
75
|
+
asa = morning
|
76
|
+
hiru = hello
|
77
|
+
ban = bye
|
78
|
+
```
|
79
|
+
|
80
|
+
|
81
|
+
```
|
82
|
+
import java.util.Locale;
|
83
|
+
import java.util.Properties;
|
84
|
+
import java.io.FileInputStream;
|
85
|
+
|
86
|
+
public class LocaleDisplay_Properties {
|
87
|
+
public static void main(String[] args) {
|
88
|
+
|
89
|
+
Locale local = Locale.getDefault();
|
90
|
+
String language = local.getLanguage();
|
91
|
+
|
92
|
+
String country;
|
93
|
+
|
94
|
+
if( "ja".equals(language) ){
|
95
|
+
country = "jp.properties";
|
96
|
+
}else{
|
97
|
+
country = "english.properties";
|
98
|
+
}
|
99
|
+
|
100
|
+
Properties properties = new Properties();
|
101
|
+
|
102
|
+
try {
|
103
|
+
FileInputStream myConfFileIn = new FileInputStream(country);
|
104
|
+
properties.load(myConfFileIn);
|
105
|
+
} catch (Exception ex) {
|
106
|
+
System.out.println("error");
|
107
|
+
}
|
108
|
+
|
109
|
+
System.out.println(properties.getProperty("asa"));
|
110
|
+
System.out.println(properties.getProperty("hiru"));
|
111
|
+
System.out.println(properties.getProperty("ban"));
|
112
|
+
|
113
|
+
}
|
114
|
+
}
|
115
|
+
```
|