vault backup: 2024-02-09 10:58:22

This commit is contained in:
2024-02-09 10:58:22 +00:00
parent 0126991874
commit 1e824525b0
18 changed files with 760 additions and 28 deletions

View File

@@ -8,10 +8,8 @@
// Import all required libraries. Not using .* as it is not good practice due to potential conflicts.
import java.util.ArrayList;
import java.util.Iterator;
import java.util.Scanner;
import java.io.File;
import java.io.PrintWriter;
import java.io.IOException;
import java.awt.FileDialog;
import java.awt.Frame;
@@ -49,32 +47,32 @@ public class Library
public void readItemData() //throws IOException
{
try {
Frame frame = null; // Initialise a null frame
FileDialog fileBox = new FileDialog( frame, "Open", FileDialog.LOAD ); // Initialise filebox with the null frame pointer
fileBox.setVisible( true ); // Open a file selection dialog to the user.
Scanner fileScanner = new Scanner( new File( fileBox.getDirectory() + fileBox.getFile() ) );
while( fileScanner.hasNextLine() )
{
try {
Scanner fileScanner = new Scanner( new File( fileBox.getDirectory() + fileBox.getFile() ) );
String lineItem = fileScanner.nextLine();
if ( !lineItem.contains( "//" ) && !lineItem.trim().isEmpty() ) { // Ensure no comments or empty lines are included
while( fileScanner.hasNextLine() )
{
Scanner detailScanner = new Scanner ( lineItem ).useDelimiter(","); // Create a new scanner to grab the values in a comma separated list
LibraryItem libraryItem = new LibraryItem();
libraryItem.readData( detailScanner );
storeItem( libraryItem ); // Store the new LibraryItem in the itemList
String lineItem = fileScanner.nextLine();
if ( !lineItem.contains( "//" ) && !lineItem.trim().isEmpty() ) { // Ensure no comments or empty lines are included
Scanner detailScanner = new Scanner ( lineItem ).useDelimiter(","); // Create a new scanner to grab the values in a comma separated list
LibraryItem libraryItem = new LibraryItem();
libraryItem.readData( detailScanner );
storeItem( libraryItem ); // Store the new LibraryItem in the itemList
}
}
}
}
catch( IOException e ) { // Catch any IO Exceptions that may occur from improper file selection.
System.err.println( "Caught IOException: " + e.getMessage() + "\nAn I/O Exception has occurred, please check file is readable and correct format." );
}
catch( IOException e ) { // Catch any IO Exceptions that may occur from improper file selection.
System.err.println( "Caught IOException: " + e.getMessage() + "\nAn I/O Exception has occurred, please check file is readable and correct format." );
}
}
}