2012-07-06 35 views
-4

我試圖將文件保存到C盤,但信息沒有得到保存到它,它仍然是空白。爲什麼?將文件保存到使用</p> <p><code>File file = new File ("C:/file.txt")</code></p> <p>該文件確實出現有一個特定的位置

當我將文件保存到源代碼的位置時,它工作正常,當我嘗試將其寫入C驅動器時,它不會保存。

+4

因爲您在代碼中存在一個錯誤。 – 2012-07-06 18:01:52

+0

@JbNizet應該是個玩笑嗎? – SkyDan 2012-07-06 18:03:38

+1

不,它應該讓OP意識到如果他沒有顯示他的代碼,我們就不能告訴他他的代碼在哪裏以及爲什麼是錯的。 – 2012-07-06 18:04:59

回答

0

嘗試下面這個例子

import java.io.*; 
public class InputStreamToFile { 
    public static void main(String args[]) { 
    try { 
     File f=new File("outFile.java"); 
     InputStream inputStream= new FileInputStream("InputStreamToFile.java"); 
     OutputStream out=new FileOutputStream(f); 
     byte buf[]=new byte[1024]; 
       int len; 
       while((len=inputStream.read(buf))>0) 
       out.write(buf,0,len); 
       out.close(); 
       inputStream.close(); 
    System.out.println("\nFile is created.........."); 
    } 
    catch (IOException e){} 
    } 
} 

enter link description here

2

嘗試......

.......寫入或讀取後關閉文件......它的重要..國家..

使用close()方法...

0

使用close()完成作業後,也可以確定,您有權限寫該文件夾

相關問題