Webサーバー上のhtmlファイルのバックアップファイルを作成しようとしています。ファイルを作成すると問題が起こります.File.getPath()は機能していないようです。
私は、バックアップを既存のファイルと同じ場所に保存したい(これは簡単な修正です)。 File file = new File(PathName)を使用してファイルを作成します。
public void backUpOldPage(String oldContent) throws IOException{
// this.uri is a class variable with the path of the file to be backed up
String fileName = new File(this.uri).getName();
String pathName = new File(this.uri).getPath();
System.out.println(pathName);
String bckPath = pathName+"\\"+bckName;
FileOutputStream fout;
try
{
// Open an output stream
fout = new FileOutputStream (bckFile);
fout.close();
}
// Catches any error conditions
catch (IOException e)
{
System.err.println ("Unable to write to file");
System.exit(-1);
}
}
代わりに、このようにbckPathを設定すると機能します。
String bckPath = "C://dev/server/tomcat6/webapps/sample-site/index_sdjf---sd.html";
私はWindowsで作業していますが、違いがあるかどうかはわかりません。
文字列bckPath = pathName + "\" + bckNameの結果。 はbckPath = C:¥dev¥server¥tomcat6¥webapps¥sample-site¥filename.htmlです。これで新しいファイルは作成されません。
多分、私はもっとコーヒーが必要ですか? :) :) – dfa
私はバックスラッシュではなくスラッシュを与えるためにFile.getPath()をどうして得るのですか – Ankur
スラッシュが必要な理由は?あなたが本当にそれをしたいと思っている場合、あなたは何が何をしているのかを知っています。この動作のためにカスタマイズクラスを考え出すことができます。 –