ファイル内の文字を置き換えて、その内容を一時ファイルにコピーし、一時ファイルの名前を元のファイルに変更したいと考えています。
path = "/mnt/sdcard/TESTfile/"
File _f = new File(path);
File[] _f1 = _f.listFiles();
String[] s1 = { "t1.txt", "t2.txt", "t3.txt" };
_fOut = new FileOutputStream(path + File.separator + s1[i]);
// Copy the bits from input stream to output stream
StringBuffer sb = null;
BufferedWriter out = null;
while ((line = reader.readLine()) != null) {
line = line.replaceAll("a"," ").replaceAll("g"," ");
sb = new StringBuffer();
Log.i("Line>>>" + line, "<<<<<");
sb.append(line);
s = sb.toString();
byte[] temp = s.getBytes();
_fOut.write(temp);
}
fis.close();
_fOut.close();
//old file name with path
String path1 = path + File.separator + s1[i];
//new file name with path
String rename1 = path + File.separator + _f1[i].getName();
File oldFile = new File(path1);
File renameFile = new File(rename1);
for(int j = 0; j < _f1.length;j++)
{
oldFile.renameTo(renameFile);
}
これが私がそれをやろうとした方法です。ファイルの名前を変更して元のファイルを削除する方法がわかりません。助けてください