gotm 0 Light Poster

So I have my text files saving perfectly from my program in the exact way I want them to. Here is a copy of the text file that my program saves that I am now trying to load back in, parse, and set up internally as another object:

scott-survey
m/c
mctext
a.b.c.d.


essay
write about me

This is just one of the samples.

Here is the code that is supposed to take in this text file and set it all up internally. When I run the code, it recognizes that the text file exists and the directory it is in, but when it goes through all the loading code I have, it seems to just return a blank survey, like it doesn't load anything right. No errors, just doesn't work right. Why?

Here is my loading code:

public survey loadSurvey(String fileName) throws SecurityException, IOException {
		
		survey loadedSurvey = new survey();
		
		
//		 all the code for reading and parsing .txt file and setting up survey (loading)
		System.out.println("What directory is your file in? ");
		String whatDir;
		BufferedReader readWhatDir = new BufferedReader(new InputStreamReader(System.in));
		whatDir = readWhatDir.readLine();
		
		File file = null;
	    FileReader freader = null;
	    LineNumberReader lnreader = null;
	    
	    try{
	    	file = new File(whatDir + fileName + ".txt");
	        freader = new FileReader(file);
	        lnreader = new LineNumberReader(freader);
	        String line = "";
	        while ((line = lnreader.readLine()) != null) {
	        	
	          if (lnreader.getLineNumber() == 0) {
	        	  loadedSurvey.setName(line);
	          }
	          else {
	        	  if ((line.equals("m/c"))) {
	    			  mc newMC = new mc();
	    			  String text = lnreader.readLine();
	    			  newMC.setQuesText(text);
	    			  String lchoices = lnreader.readLine();
	    			  while (lchoices.indexOf(".") != -1) {
	    				  lchoices = lchoices.substring(0, lchoices.indexOf("."));
	    				  newMC.addLeftChoice(lchoices);
	    			  }
	    			  String rchoices = lnreader.readLine();
	    			  while (rchoices.indexOf(".") != -1) {
	    				  rchoices = rchoices.substring(0, rchoices.indexOf("."));
	    				  newMC.addRightChoice(rchoices);
	    			  }
	    			  String answer = lnreader.readLine();
	    			  newMC.setQuesAnswer(answer);
	    			  loadedSurvey.addQues(newMC);
	    		  }
	        	  else if ((line.equals("t/f"))) {
	    			  tf newTF = new tf();
	    			  String text = lnreader.readLine();
	    			  newTF.setQuesText(text);
	    			  
	    			  // here there is always just T and F but the save function creates two empty lines
	    			  // just readLine() twice to get to the user answer
	    			  for (int i = 0; i < 2; i++) {
	    				  lnreader.readLine();
	    			  }
	    			  
	    			  String answer = lnreader.readLine();
	    			  newTF.setQuesAnswer(answer);
	    			  loadedSurvey.addQues(newTF);
	    		  }
	        	  else if ((line.equals("matching"))) {
	    			  matching newMatching = new matching();
	    			  String text = lnreader.readLine();
	    			  newMatching.setQuesText(text);
	    			  String lchoices = lnreader.readLine();
	    			  while (lchoices.indexOf(".") != -1) {
	    				  lchoices = lchoices.substring(0, lchoices.indexOf("."));
	    				  newMatching.addLeftChoice(lchoices);
	    			  }
	    			  String rchoices = lnreader.readLine();
	    			  while (rchoices.indexOf(".") != -1) {
	    				  rchoices = rchoices.substring(0, rchoices.indexOf("."));
	    				  newMatching.addRightChoice(rchoices);
	    			  }
	    			  String answer = lnreader.readLine();
	    			  newMatching.setQuesAnswer(answer);
	    			  loadedSurvey.addQues(newMatching);
	    		  }
	        	  else if ((line.equals("ranking"))) {
	    			  ranking newRanking = new ranking();
	    			  String text = lnreader.readLine();
	    			  newRanking.setQuesText(text);
	    			  String lchoices = lnreader.readLine();
	    			  while (lchoices.indexOf(".") != -1) {
	    				  lchoices = lchoices.substring(0, lchoices.indexOf("."));
	    				  newRanking.addLeftChoice(lchoices);
	    			  }
	    			  
	    			  // right choices are just the numbers to be ranked which is in the constructor
	    			  // just perform one readLine() to get to next line
	    			  lnreader.readLine();
	    			  
	    			  String answer = lnreader.readLine();
	    			  newRanking.setQuesAnswer(answer);
	    			  loadedSurvey.addQues(newRanking);
	    		  }
	        	  else if ((line.equals("essay"))) {
	    			  essay newEssay = new essay();
	    			  String text = lnreader.readLine();
	    			  newEssay.setQuesText(text);
	    			  String answer = lnreader.readLine();
	    			  newEssay.setQuesAnswer(answer);
	    			  loadedSurvey.addQues(newEssay);
	    		  }
	        	  else if ((line.equals("s/a"))) {
	    			  sa newSA = new sa();
	    			  String text = lnreader.readLine();
	    			  newSA.setQuesText(text);
	    			  String answer = lnreader.readLine();
	    			  newSA.setQuesAnswer(answer);
	    			  loadedSurvey.addQues(newSA);
	    		  }
	          }
	          
	        }
	      }
	    
	      finally {
	    	  
	        freader.close();
	        lnreader.close();
	        
	      }
	    
	   return loadedSurvey;
	}
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.