I"m trying to make program that keeps track of stocked inventory of goods. The information about the goods is then saved in a .txt file in the following format. 1st line is name of the article, 2nd line is the day that stock was bought, 3rd line is the amount of stock that was bought for a certain article. I need to read this third line of text which only contains numerical data, assign it to a variable and recover the numerical value so that I can make overwrite the data whenever new stock is bought.
I've used FileReader along with BufferedReader to read the lines in the .txt file. The problems comes when I try to implement the loop to read the lines. I've tried a for and a while loop and neither worked. I keep getting an unreported exception error.
Code
try
{
FileReader fr = new FileReader("C:/Users/Gian/Documents/COMP 2400/test/"+ file + ".txt");
BufferedReader br = new BufferedReader(fr);
while (c < 2) {
br.readLine();
line = br.readLine();
c++;
}
}
catch (FileNotFoundException fe)
I also tried it like this:
try
{
FileReader fr = new FileReader("C:/Users/Gian/Documents/COMP 2400/test/"+ file + ".txt");
BufferedReader br = new BufferedReader(fr);
for(int i; i<2;, i++){
br.readLine();
line = br.readLine();
}
}
catch (FileNotFoundException fe)
I keep getting this error:
Purchase_Inventory.java:34: error: unreported exception IOException; must be caught or declared to be thrown
br.readLine();
^
Purchase_Inventory.java:35: error: unreported exception IOException; must be caught or declared to be thrown
line = br.readLine();