求最高效的Java向文本追加字符串的代码!
public void updateAll4Tex(String file,String url) throws Exception{
GetAllMessage gam=new GetAllMessage();
ArrayList<String[][]> al =gam.getAllMsg(url);
int i=0;
int k=al.size();
while (i<k){
String[][] str=al.get(i);
if(str instanceof String[][]){
for(int j=0;j<str.length;j++){
write(file,str[j][1]);
// System.out.print(str[j][0]+":");
// System.out.println(str[j][1]);
}
}
i++;
}
//下面这两行数据需要追加进去的,有点长的
// System.out.println(al.size());
// System.out.println(al.size());
}
public void updateAll4Tex(String file,String url) throws Exception{
GetAllMessage gam=new GetAllMessage();
ArrayList<String[][]> al =gam.getAllMsg(url);
int i=0;
int k=al.size();
while (i<k){
String[][] str=al.get(i);
if(str instanceof String[][]){
for(int j=0;j<str.length;j++){
write(file,str[j][1]);
// System.out.print(str[j][0]+":");
// System.out.println(str[j][1]);
}
}
i++;
}
//下面这两行数据需要追加进去的,有点长的
// System.out.println(al.size());
// System.out.println(al.size());
}
这有啥高效不高效的问题?...
文件打开 -> 写入 -> 关闭
还能咋样?
//该方法直接读取文件后
BufferedWriter bw = new BufferedWriter(new FileWriter(new File("d:\\test.txt"),true));
bw.write(" 追加的内容 ");
bw.close();
} catch (IOException e) {
e.printStackTrace();
}