ITPub博客

首页 > 应用开发 > Java > 非常有用的Java功能代码

非常有用的Java功能代码

原创 Java 作者:tchen 时间:2011-10-14 14:11:06 0 删除 编辑

1. 把Strings转换成int和把int转换成String

String a = String.valueOf(2); 
//integer to numeric string  
int i = Integer.parseInt(a); //numeric string to an int

String 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();
}
}

[@more@]

来自 “ ITPUB博客 ” ,链接:https://blog.itpub.net/122642/viewspace-1055677/ ,如需转载,请注明出处,否则将追究法律责任。

上一篇: OAF—分析页面1
请登录后发表评论 登录
全部评论

注册时间:2010-06-29

  • 博文量
    19
  • 访问量
    88887