2016-03-24 10 views
0

EDIT Liste listemdeki değerlere sahip listemimŞimdi şimdi bu listeye fazladan değer eklemek istiyorum.Liste <File>'dan dosyaya yolunu bulup başka bir listeye koyma

Ve ben bu [günlüğünden değer] gibi liste var befor i yolunu almak ve i .getAbsolutePath kullanırsanız Alse kod eklemek gerekir bilmiyorum bu

private static List<String> listQuestionE(Scanner sc, List<File> listQuestion){ 
     //List with value from List<File> listQuestion (its some value from .log files it doesn't matter 
     List<String> question = new ArrayList<String>(); 
     //I think that I need to do something with File input1 but i try several things and it doesnt work for me. 
     for(File input1 : listaQuestion){ 
      try { 
       sc = new Scanner(input1); 
      } catch (FileNotFoundException e) { 
       e.printStackTrace(); 
      } 

    while(sc.hasNextLine()){ 
     s = new Scanner(sc.nextLine()); 
     while(s.hasNext()){ 

      String words = s.nextLine(); 
      if(!getTagValues(words).isEmpty()){ 
       try { 

        question.add(getTagValues(words).toString()); 

       } catch (Exception e) { 
        // TODO Auto-generated catch block 
        e.printStackTrace(); 
       } 
      } 
     } 
     } 
    } 
     return question; 
    } 

gibi Benim kod bakmak , [Yol] veya en kötü [], [Yol], çünkü bazen günlüğe kaydetme hatası olmadığından cevap boştur.

+2

Kodda bu dosyayı kullanmak ister misiniz? Anlam çok açık değil. Lütfen soruyu net bir şekilde düzenleyin. –

+1

Tamam, pardon ama burada ne sorduğun hakkında hiçbir fikrim yok. –

+0

kodunuzu biçimlendirin ve sorularınız için lütfen –

cevap

0

Dosya nesnesinden dosya yolunu belirlemeye çalışıyorsanız, Java 7'yi kullanarak bunu yapabilirsiniz.

file.getAbsolutePath() // where file is a reference to File object 

Bu soyut yol adının mutlak yol adı dizesini döndürür.

private static List<String> listQuestionE(Scanner sc, List<File> listQuestion){ 

     List<String> question = new ArrayList<String>(); 
     for(File input1 : listQuestion){ 
      try { 
       String fPath = input1.getAbsolutePath(); 
       sc = new Scanner(input1); 
       question.add(fPath); 
      } catch (FileNotFoundException e) { 
       e.printStackTrace(); 
      } 
     } 
     return question; 
} 
+0

Cevabınız çabucak değerlendirir :) Çözümünüzü deneyip ASAP yeniden oynatırım –

İlgili konular