首页 > 应用开发 > Java > 非常有用的Java功能代码
1. 把Strings转换成int和把int转换成String
String a = String.valueOf(2); //integer to numeric string[@more@]
int i = Integer.parseInt(a); //numeric string to an intString a = String.valueOf(2); //integer to numeric string
int i = Integer.parseInt(a); //numeric string to an int向Java文件中添加文本
Updated: Thanks Simone for pointing to exception. I have changed the code.
BufferedWriter ut = null;
try {
out = new BufferedWriter(new FileWriter(” filename”, true));
out.write(” aString”);
} catch (IOException e) {
// error processing code
} finally {
if (out != null) {
out.close();
}
}
BufferedWriter ut = null;
try {
out = new BufferedWriter(new FileWriter(”filename”, true));
out.write(”aString”);
} catch (IOException e) {
// error processing code
} finally {
if (out != null) {
out.close();
}
}
来自 “ ITPUB博客 ” ,链接:https://blog.itpub.net/122642/viewspace-1055677/ ,如需转载,请注明出处,否则将追究法律责任。