2017-11-02 4 views
1

Ich möchte eine ArrayList in einer Textdatei speichern und später erneut lesen. mein Code:android - Pfade.get (Dateiname); für api 16

public static ArrayList readFromFile(String filename){ 
    ArrayList<String> myList = new ArrayList<String>(); 
    try{ 
     Scanner sc = new Scanner(new File(filename)); 
     while(sc.hasNextLine()){ 
      myList.add(sc.nextLine()); 
     } 
     sc.close(); 
    }catch (FileNotFoundException e){ 
     e.printStackTrace(); 
    } 
    return myList; 
} 

public static void saveToFile(String fileName, ArrayList list){ 
    Path filePath = Paths.get(fileName); 

    try { 
     Files.write(filePath, list, Charset.defaultCharset()); 
    } catch (IOException e) { 
     e.printStackTrace(); 
    } 
} 

Aber ich habe zwei Probleme: 1. Paths.get(); ist nur verwendbar seit api 26 2. ich kann diesen code nicht testen weil ich einen amd pc habe und es gibt keinen emulator für api 26

Antwort

Verwandte Themen