import java.io.BufferedWriter; import java.io.FileWriter; import java.io.IOException; import java.nio.file.Files; import java.nio.file.Paths; import java.util.ArrayList; import java.util.List; /**GeneralMethods is a class for commen public methods. * * @auhtor Felix Wöstemeyer * * @version 1.0 */ public class GeneralMethods { /**The method readData gives back an ArrayList from the data of a given file. * * @param pathRead the given filepath to read * @return returns an ArrayList of Strings with the read data */ public static ArrayList readData(String pathRead){ try { ArrayList data = new ArrayList(); List lines = Files.readAllLines(Paths.get(pathRead)); for(String line : lines){ data.add(line); } return data; } catch (IOException e) { e.printStackTrace(); return new ArrayList(); } } /**The method writeData saves the given data to a certain file. * * @param pathWrite the given filepath to write * @param data the data to be saved */ public static void writeData(String pathWrite, ArrayList data){ try{ BufferedWriter writer = new BufferedWriter(new FileWriter(pathWrite)); for (String d : data) { writer.write(d); writer.newLine(); } writer.close(); } catch (IOException e) { e.printStackTrace(); } } }