2016-07-28 6 views
0
try{ 
    pw = new PrintWriter("C:\\Users\\SDSAD\\Desktop\\java\\file.txt"); 
}catch(Exception exc){ 
    System.out.println(); 
} 

を入力することができません:のPrintWriterは私がちょうど最近IOで遊んでされて、私はPrintWriterを使用しようとしていたと私はちょうど置くとき、それは例えばのように、最初に勤務していた特定のディレクトリに

pw = new PrintWriter("file.txt"); 

それは完全に正常に働いた、私はPrintWriterで特定のディレクトリを設定することを許可されていないか、何か間違っている?あなたは、ディレクトリ上で実行したとき、それが何を期待するかどう

* @param fileName 
*   The name of the file to use as the destination of this writer. 
*   If the file exists then it will be truncated to zero size; 
*   otherwise, a new file will be created. The output will be 
*   written to the file and is buffered. 

答えて

2

のPrintWriterは、Javadocを参照してください、ファイルのみに使用すべきですか?

EDIT:質問が変更された後。

あなたはすべてうまくやっていますが、指定したディレクトリにそのファイルがないか、アクセスするための読み取り権限がないと思います。

+0

私の最後にはTypo、最初は最後に私はfile.txtを持っていました。私の悪い。 – zzzzzz

関連する問題