0

It's only reading every other line. It's supposed to print out:
28
80.0
22
1
2
2
3
1
3

But it's only reading:
80.0
1
2
1

//Load button - #=daynum, $=wallet, @=inventory, &=employees, !=customers
		            	if (btn2.getText().equals("Load")){
		            		int id=0;
		            		File file = new File("savefile1.txt");
		            		BufferedReader reader = null;
		            		
		            		try {
		            			reader = new BufferedReader(new FileReader(file));
		            			String text = null;
		            		
		            			while ((text = reader.readLine()) != null) {
		            				text = reader.readLine();
		            				if (text.contains("#")){
		            					text=text.replace("#", "");
		            					dayNum=Integer.parseInt(text);
		            				}
		            				if (text.contains("$")){
		            					text=text.replace("$", "");
		            					wallet=Double.parseDouble(text);
		            				}
		            				if (text.contains("!")){
		            					text=text.replace("!", "");
		            					customer.setCustTotalComplete(Integer.parseInt(text));
		            				}
		            				if (text.contains("@")){
		            					text=text.replace("@", "");
		            					id=Integer.parseInt(text);
		            					BuyInvItem(id);
		            					inventory.setNewInv(InvId[id],
	        									InvPrice[id],
	        									InvName[id],
	        									InvSellPrice[id],
	        									InvAmt[id],
	        									InvBuyPrice[id], id);
		            				}
		            				if (text.contains("&")){
		            					text=text.replace("&", "");
		            					id=Integer.parseInt(text);
		            					employee.setNewEmp(EmpId[id],
	        									EmpWage[id],
	        									EmpName[id],
	        									EmpSpeed[id], 
	        									id);
		            				}
		            			}//end while
		            			MainText();
		            			UpdateEmpDisplay();
		            			UpdateInvDisplay();
		            			txtSide.setText(MainText);
		            		}//end try
		            		catch (FileNotFoundException f) {
		            			f.printStackTrace();
		            			JOptionPane.showMessageDialog(null, "Save file not found");
		            		}
		            		catch (IOException f) {
		            			f.printStackTrace();
		            			JOptionPane.showMessageDialog(null, "There was an error loading the file");
		            		}
		            		catch (NullPointerException f){
		            			JOptionPane.showMessageDialog(null, "File loaded successfully");
		            		}
		            		finally {
		            			try {
		            				if (reader != null) {
		            					reader.close();
		            				}
		            			} catch (IOException f) {
		            				f.printStackTrace();
		            			}
		            		}
		            	}

HELP ME PLZ

2
Contributors
2
Replies
4
Views
6 Years
Discussion Span
Last Post by Slyvr
0
while ((text = reader.readLine()) != null) {
		            				text = reader.readLine();
		            				if (text.contains("#")){

The reason it only displays every other line is that you read each line twice. Once, when you check to see if the while loop is still good, again when you store it as the variable 'text'. Since you're already storing the next line (reader.readLine()) in the while loop, just drop the second readline:

while ((text = reader.readLine()) != null) {
		            				if (text.contains("#")){
0

Ahhh, thank you. A second pair of eyes is always helpful for catching these silly little things ;)

This question has already been answered. Start a new discussion instead.
Have something to contribute to this discussion? Please be thoughtful, detailed and courteous, and be sure to adhere to our posting rules.