任何人都可以請告訴我如何刪除目錄中的文件打開並加載到數據庫後?如何使用Java從目錄中刪除文件?
這裏是我的代碼:
public static void main(String[] args) throws SQLException{
int Count= 0;
File directory = new File("C://Documents and Settings//welcome//My Documents//Bluetooth Exchange Folder");
directory.deleteOnExit();
File files[] = directory.listFiles();
for(int index = 0; index < files.length; index++){
try {
FileReader inp = new FileReader (files[index]);
BufferedReader buf = new BufferedReader(inp);
String strLine;
try {
while ((strLine = buf.readLine()) != null)
{
System.out.println(strLine);
String[] dbColumnValues = strLine.split("%");
Connect.DoInsertIntoDB(Long.parseLong(dbColumnValues[0]),dbColumnValues[1],dbColumnValues[2], dbColumnValues[3]);
Count++;
System.out.println(Count + " Row(s) are inserted into the Database");
GenHTML.gen();
}
}
但文件沒有在目錄中刪除。 請任何人都可以糾正我的代碼中的錯誤?
[目前,我正在測試目錄中的3個文件。之後的每個文件被加載到datbase,我希望每個文件來從目錄中刪除。]提前
謝謝!
這應該是一個評論,而不是一個答案。 – 2011-04-13 19:05:48
但實際上,文件中的數據正在被正確加載到數據庫中,這意味着目錄中的文件被識別。所以,我猜,斜線不是問題 – Anu 2011-04-13 19:09:49