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

Recommended Answers

All 2 Replies

Member Avatar for ztini
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("#")){

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

Be a part of the DaniWeb community

We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.