[英]How Can I create a new Directory with the last element of the linkedList for each line of the file
我的文本文件包含3列ID tweet分類
我想為分類的每個元素創建一個新目錄,所以我創建了一個鏈接列表以獲取上一個索引並創建了一個目錄,但是它可以有效地解決我的問題嗎? 謝謝這是我的代碼:
//Create a linked list
LinkedList <String> fileLinkedList = new LinkedList<String>();
fileLinkedList.add(line.toString());//line is a String variable that contains buff.readLine();
System.out.println(fileLinkedList);
for(int i = 0; i < fileLinkedList.size();i++){
File LinkedFile = new File(fileLinkedList.getLast().toString());
fileLinkedList.add(line);
System.out.println(fileLinkedList);
if(LinkedFile.mkdirs()){
System.out.println("make dir");
}else{
System.out.println("doesnt work");
}
}
據我了解,您有一個包含以下三列的文件:
ID1 tweet1 Classification1
ID2 tweet2 Classification2
ID3 tweet3 Classification3
ID4 tweet4 Classification4
您要讀取此文件的行,僅獲得“ Classification
列,並將其添加到鏈接列表中,然后創建一個新目錄,其最后一個元素的名稱為“ Classification
BufferedReader bufferedReader = new BufferedReader(new InputStreamReader("File directory"));
LinkedList<String> fileLinkedList = new LinkedList<String>();
String line;
while ((line = bufferedReader.readLine()) != null) {
fileLinkedList.add(line.split(" ")[2]);
for(int i = 0; i < fileLinkedList.size();i++){
File LinkedFile = new File(fileLinkedList.removeLast());
if(LinkedFile.mkdirs()){
System.out.println("make dir");
}else{
System.out.println("doesnt work");
}
}
}
並要小心,如果您僅在new File()
一個目錄名,它將在您工作區的項目目錄中創建目錄。
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.