80,349
社区成员
发帖
与我相关
我的任务
分享
public class MainActivity extends Activity {
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_main);
Properties prop = new Properties();
prop.setProperty("IssueType", "xixixi");
prop.setProperty("Frequency", "哈哈");
prop.setProperty("Description", "123");
prop.setProperty("ContactInfo","heihei");
String path = Environment.getExternalStorageDirectory().getPath() + "/1.txt";
Log.v("path",path);
saveConfig(path, prop);
}
public void saveConfig(String file, Properties properties) {
try {
FileOutputStream s = new FileOutputStream(file, false);
BufferedWriter bw = new BufferedWriter(new OutputStreamWriter(s, "utf-8"));
properties.store(bw, "");
s.close();
} catch (Exception e){
e.printStackTrace();
}
}
}
public class test123 {
public static void main(String[] args) {
Properties prop = new Properties();
int issueType = 1;
int frequency = -1;
String description = "123131234124";
String contactInfo = "1234567";
prop.setProperty("IssueType", "呵呵");
prop.setProperty("Frequency", "12345");
prop.setProperty("Description", description);
prop.setProperty("ContactInfo", contactInfo);
saveConfig("c:/1.txt", prop);
}
static public void saveConfig(String file, Properties properties) {
try {
FileOutputStream s = new FileOutputStream(file, false);
BufferedWriter bw = new BufferedWriter(new OutputStreamWriter(s, "utf-8"));
properties.store(bw, "");
s.close();
} catch (Exception e){
e.printStackTrace();
}
}
}
Frequency=\u54c8\u54c8
这是改不了的,除非你不用Properties类,因为在Properties类里已经写死了:
private void dumpString(StringBuilder buffer, String string, boolean key) {
int i = 0;
if (!key && i < string.length() && string.charAt(i) == ' ') {
buffer.append("\\ ");
i++;
}
for (; i < string.length(); i++) {
char ch = string.charAt(i);
switch (ch) {
case '\t':
buffer.append("\\t");
break;
case '\n':
buffer.append("\\n");
break;
case '\f':
buffer.append("\\f");
break;
case '\r':
buffer.append("\\r");
break;
default:
if ("\\#!=:".indexOf(ch) >= 0 || (key && ch == ' ')) {
buffer.append('\\');
}
if (ch >= ' ' && ch <= '~') {
buffer.append(ch);
} else {
String hex = Integer.toHexString(ch);
buffer.append("\\u");
for (int j = 0; j < 4 - hex.length(); j++) {
buffer.append("0");
}
buffer.append(hex);
}
}
}
}