Package io.github.astrapisixtynine.csv
Klasse CsvFileExtensions
java.lang.Object
io.github.astrapisixtynine.csv.CsvFileExtensions
Utility class for the use of cvs-files.
-
Methodenübersicht
Modifizierer und TypMethodeBeschreibungformatKommaSeperatedFileToList
(File input, String encoding) Reads every line from the File splits the data through a comma and puts them to the List.static void
formatToCSV
(File input, File output, String encoding) Formats a file that has in every line one input-data into a csv-file.getCvsAsListMap
(File input) Gets the given cvs file as list of maps.getCvsAsListMap
(File input, String encoding) Gets the given cvs file as list of maps.static String[]
getDataFromLine
(String line, String seperator) Gets the data from line.static String[]
getDataFromLine
(String line, String seperator, boolean trim) Gets the data from line.static int
getLineCountFromCsvFile
(File file) Gets the line count from csv file.readDataFromCVSFileToList
(File input, int position, boolean putFirstLine, String encoding) Reads from a csv-file the field from the given position and puts them to the List.readDataFromCVSFileToList
(File input, int position, boolean putFirstLine, String splitChar, String encoding) Reads from a csv-file the field from the given position and puts them to the List.static Properties
readFilelistToProperties
(File input) Read filelist to properties.readFileToList
(File file) Reads every line from the given File into a List and returns the List.readFileToList
(File file, String encoding) Reads every line from the given File into a List and returns the List.readFileToList
(File file, String seperator, String encoding) Reads every line from the given File into a List of String arrays and returns the List.readLinesInList
(File input, String encoding) Reads every line from the File and puts them to the List.static String[]
Read an csv-file and puts them in a String-array.static void
storeFilelistToProperties
(File output, File input, String comments) Stores a komma seperated file to a properties object.static void
writeLines
(File output, Set<String> values, String encoding) Writes the toString() value of each item in a collection to the specified File line by line.static void
writeLinesToFile
(Collection<String> collection, File output, String encoding) Writes all the String-object in the collection into the given file.
-
Methodendetails
-
formatKommaSeperatedFileToList
public static List<String> formatKommaSeperatedFileToList(File input, String encoding) throws IOException Reads every line from the File splits the data through a comma and puts them to the List.- Parameter:
input
- The File from where the input comes.encoding
- The encoding from the file.- Gibt zurück:
- The List with all lines from the file.
- Löst aus:
IOException
- Signals that an I/O exception has occurred.
-
formatToCSV
Formats a file that has in every line one input-data into a csv-file.- Parameter:
input
- The input-file to format. The current format from the file is every data in a line.output
- The file where the formatted data should be inserted.encoding
- the encoding- Löst aus:
IOException
- When an io error occurs.
-
getCvsAsListMap
Gets the given cvs file as list of maps. Every map has as key the header from the column and the corresponding value for this line.- Parameter:
input
- the input- Gibt zurück:
- the cvs as list map
- Löst aus:
IOException
- Signals that an I/O exception has occurred.
-
getCvsAsListMap
public static List<Map<String,String>> getCvsAsListMap(File input, String encoding) throws IOException Gets the given cvs file as list of maps. Every map has as key the header from the column and the corresponding value for this line.- Parameter:
input
- the inputencoding
- the encoding to read- Gibt zurück:
- the cvs as list map
- Löst aus:
IOException
- Signals that an I/O exception has occurred.
-
getDataFromLine
Gets the data from line.- Parameter:
line
- the lineseperator
- the seperator- Gibt zurück:
- the data from line
-
getDataFromLine
Gets the data from line.- Parameter:
line
- the lineseperator
- the seperatortrim
- the trim- Gibt zurück:
- the data from line
-
getLineCountFromCsvFile
Gets the line count from csv file.- Parameter:
file
- the file- Gibt zurück:
- the line count from csv file
- Löst aus:
IOException
- Signals that an I/O exception has occurred.
-
readDataFromCVSFileToList
public static List<String> readDataFromCVSFileToList(File input, int position, boolean putFirstLine, String encoding) throws IOException Reads from a csv-file the field from the given position and puts them to the List.- Parameter:
input
- The input-file.position
- The position from the field.putFirstLine
- Flag that tells if the first line will be put in the list.encoding
- the encoding- Gibt zurück:
- The list with the data.
- Löst aus:
IOException
- When a io-problem occurs.
-
readDataFromCVSFileToList
public static List<String> readDataFromCVSFileToList(File input, int position, boolean putFirstLine, String splitChar, String encoding) throws IOException Reads from a csv-file the field from the given position and puts them to the List.- Parameter:
input
- The input-file.position
- The position from the field.putFirstLine
- Flag that tells if the first line will be put in the list.splitChar
- the split charencoding
- the encoding- Gibt zurück:
- The list with the data.
- Löst aus:
IOException
- When a io-problem occurs.
-
readFilelistToProperties
Read filelist to properties.- Parameter:
input
- the input- Gibt zurück:
- the properties
- Löst aus:
IOException
- Signals that an I/O exception has occurred.
-
readFileToList
Reads every line from the given File into a List and returns the List.- Parameter:
file
- The file from where to read.- Gibt zurück:
- The List with all lines from the File.
- Löst aus:
IOException
- When a io-problem occurs.
-
readFileToList
Reads every line from the given File into a List and returns the List.- Parameter:
file
- The file from where to read.encoding
- The encoding to read.- Gibt zurück:
- The List with all lines from the File.
- Löst aus:
IOException
- When a io-problem occurs.
-
readFileToList
public static List<String[]> readFileToList(File file, String seperator, String encoding) throws IOException Reads every line from the given File into a List of String arrays and returns the List.- Parameter:
file
- The file from where to read.seperator
- the seperatorencoding
- The encoding to read.- Gibt zurück:
- The List with all lines from the File.
- Löst aus:
IOException
- Signals that an I/O exception has occurred.
-
readLinesInList
Reads every line from the File and puts them to the List.- Parameter:
input
- The File from where the input comes.encoding
- The encoding from the file.- Gibt zurück:
- The List with all lines from the file.
- Löst aus:
IOException
- When a io-problem occurs.
-
sortData
public static String[] sortData(File csvData, String encoding) throws FileNotFoundException, IOException Read an csv-file and puts them in a String-array.- Parameter:
csvData
- The csv-file with the data.encoding
- The encoding to read.- Gibt zurück:
- The data from the csv-file as a String-array.
- Löst aus:
FileNotFoundException
- is thrown if the given file is not foundIOException
- When an io-error occurs.
-
storeFilelistToProperties
public static void storeFilelistToProperties(File output, File input, String comments) throws IOException Stores a komma seperated file to a properties object. As key is the number from the counter.- Parameter:
output
- the outputinput
- the inputcomments
- the comments- Löst aus:
IOException
- Signals that an I/O exception has occurred.
-
writeLines
Writes the toString() value of each item in a collection to the specified File line by line. The default VM encoding and the default line ending will be used.- Parameter:
output
- The File where the values to save.values
- The Set with the values to put into the file.encoding
- The encoding from the file.- Löst aus:
IOException
- When a io-problem occurs.
-
writeLinesToFile
public static void writeLinesToFile(Collection<String> collection, File output, String encoding) throws IOException Writes all the String-object in the collection into the given file.- Parameter:
collection
- The collection with the String-object.output
- The file where the String-object will be writing.encoding
- The encoding from the file.- Löst aus:
IOException
- Signals that an I/O exception has occurred.
-