Skip to content

Commit

Permalink
Updated FileHandler
Browse files Browse the repository at this point in the history
Added JavaDoc.
  • Loading branch information
roaraf committed Mar 27, 2026
1 parent 0938229 commit 07f133a
Showing 1 changed file with 19 additions and 4 deletions.
23 changes: 19 additions & 4 deletions millions/src/main/java/no/ntnu/gruppe53/FileHandler.java
Original file line number Diff line number Diff line change
Expand Up @@ -11,9 +11,19 @@
import java.util.ArrayList;
import java.util.List;

/**
* Handles file operations for the application.
*/

public class FileHandler {

/**
* Writes a list of {@link Stock}s to a text-file. Class is structed for {@code .csv} files.
*
* @param stockList the list of stocks to be converted to text
* @param path output path for the file
* @param filename name of the file (not including extension)
*/
public static void writeStocksToFile(List<Stock> stockList, String path, String filename) {
String pathString = path + filename;
Path filePath = Paths.get(pathString);
Expand All @@ -40,6 +50,13 @@ public static void writeStocksToFile(List<Stock> stockList, String path, String
}
}

/**
* Reads a .csv file and converts it to a list of {@code Stock} objects.
*
* @param path path to the file to be read
* @param filename name of the file to be read (including extension)
* @return a list of {@code Stock} objects converted from text
*/
public static List<Stock> readStocksFromFile(String path, String filename) {
List<Stock> stocks = new ArrayList<>();
String pathString = path + filename;
Expand Down Expand Up @@ -101,13 +118,11 @@ public static List<Stock> readStocksFromFile(String path, String filename) {
}
stocks.add(new Stock(symbol, name, price));
}

} catch (IOException e) {
}
catch (IOException e) {
System.out.println("ERROR: Something went wrong while reading the csv file.");
System.out.println("Message: " + e.getMessage());
}

return stocks;
}

}

0 comments on commit 07f133a

Please sign in to comment.