So I've got a text file:
Name: Hulabaloo
Loading bay: 7
Container handling time: 50ms
Storage capacity: 70
and I want to extract this information to create an object in my class for similar variables as those in the text file. I've figured it out up till the point of reading the file, here's my code:
public class ThisClass
{
private static final URL path = ThisClass.class.getResource("TextFile.info");
private static final String TEXTFILE = path.getFile();
private String name;
private int loadingBays;
private int containerHandlingTime;
private int storageCapacity;
public ThisClass(String name, int loadingBays, int containerHandlingTime,
int storageCapacity)
{
this.name = name;
this.loadingBays = loadingBays;
this.containerHandlingTime = containerHandlingTime;
this.storageCapacity = storageCapacity;
}
public static void main(String[] args) throws FileNotFoundException, IOException
{
BufferedReader br = null;
FileReader fr = null;
String sCurrentLine;
br = new BufferedReader(new FileReader(TEXTFILE));
while((sCurrentLine = br.readLine()) != null)
{
System.out.println(sCurrentLine);
}
}
}
Well obviously all this does is print the textfile out. What I want to be doing is creating an object from the Harbour class and passing the values from the text file into the constructor. I thought trying to look for ": " in the text file and extracting from that point to the end of the line would be a good idea but I don't know how to do that. I would greatly appreciate any help on the matter, thanks in advance!