This commit is contained in:
2022-11-24 13:59:26 +01:00
commit 88d1b3a1af
12 changed files with 115 additions and 0 deletions

13
src/Execute.java Normal file
View File

@@ -0,0 +1,13 @@
import java.util.ArrayList;
/**The class Execute is the executen file for the whole programm.
*/
public class Execute {
public static void main (String[]args){
ArrayList<String> data = GeneralMethods.readData("test.csv");
for(String d : data){
System.out.println(d);
}
GeneralMethods.writeData("test2.csv",data);
}
}

53
src/GeneralMethods.java Normal file
View File

@@ -0,0 +1,53 @@
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<String> readData(String pathRead){
try {
ArrayList<String> data = new ArrayList<String>();
List<String> lines = Files.readAllLines(Paths.get(pathRead));
for(String line : lines){
data.add(line);
}
return data;
} catch (IOException e) {
e.printStackTrace();
return new ArrayList<String>();
}
}
/**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<String> 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();
}
}
}