Welcome to the Java Programming Forums


The professional, friendly Java community. 21,500 members and growing!


The Java Programming Forums are a community of Java programmers from all around the World. Our members have a wide range of skills and they all have one thing in common: A passion to learn and code Java. We invite beginner Java programmers right through to Java professionals to post here and share your knowledge. Become a part of the community, help others, expand your knowledge of Java and enjoy talking with like minded people. Registration is quick and best of all free. We look forward to meeting you.


>> REGISTER NOW TO START POSTING


Members have full access to the forums. Advertisements are removed for registered users.

Results 1 to 2 of 2

Thread: Help displaying strings that appear in one text file but not another!

  1. #1
    Junior Member
    Join Date
    Mar 2012
    Posts
    2
    Thanks
    0
    Thanked 0 Times in 0 Posts

    Angry Help displaying strings that appear in one text file but not another!

    I'm trying to display all of the songs that appear in one text file but not another. However it doesn't display any songs. All help appreciated.
    My Code:
    	  public static void OnlyInIrishCharts()throws IOException
        {
    		String lineFromFile, line;
    		String result;
      		String words [];
      		String peices [];
      		int count = 1;
      		boolean found;
      		result = "The following singles only appear in the Irish Charts: ";
    		File f1 = new File("IrishTop100Singles.txt");
    		File f2 = new File("UKTop100Singles.txt");
    		if (f1.exists() && f2.exists())
      		{
       			Scanner input = new Scanner(f1);
       			while(input.hasNext())
       			{
        			lineFromFile = input.nextLine();
        			words = lineFromFile.split(";");
        			Scanner input2 = new Scanner(f2);
        			found = false;
        			while(input2.hasNext() && !found)
        			{
    	    			line = input2.nextLine();
    	    			peices = line.split(";");
    	    			if(!(words[2].equals(peices[2])) && !(words[3].equals(peices[3])))
    	    			 found = true;
    				}
     
    				input2.close();
    				if (found = false)
    				{
    					result += (count + ". Title: " + (words[2]) + " Artist: " + (words[3]) + "\n");
    					count++;
    				}
    			}
     
    			JOptionPane.showMessageDialog(null,result,"UK and Irish Charts",1);
    			input.close();
    		}
    		else
      			JOptionPane.showMessageDialog(null,"File Not Found!", "Error!",0);
     
    	}


  2. #2
    Super Moderator Norm's Avatar
    Join Date
    May 2010
    Location
    Eastern Florida
    Posts
    25,140
    Thanks
    65
    Thanked 2,720 Times in 2,670 Posts

    Default Re: Help displaying strings that appear in one text file but not another!

    it doesn't display any songs
    Try debugging the code by adding println statements to show where the execution flow goes and to show the values of variables used in the code. The print out will show you what the computer sees and will help you understand what the problem is.
    If you don't understand my answer, don't ignore it, ask a question.

Similar Threads

  1. Read Text File Into Strings
    By Khadafi in forum Java Theory & Questions
    Replies: 31
    Last Post: January 14th, 2012, 09:29 AM
  2. displaying dyanamic data on jsp while core engine is writing it on text file
    By abhyudayaupadhyay in forum File I/O & Other I/O Streams
    Replies: 5
    Last Post: May 24th, 2011, 10:03 AM
  3. [SOLVED] Reading integers from a file, but it's only displaying the first number repeatedly..?
    By jessica202 in forum What's Wrong With My Code?
    Replies: 5
    Last Post: March 29th, 2011, 08:16 AM
  4. reading content of the text file, splitting it into strings
    By Dodo in forum File I/O & Other I/O Streams
    Replies: 7
    Last Post: January 6th, 2011, 07:57 PM
  5. java program to copy a text file to onother text file
    By francoc in forum File I/O & Other I/O Streams
    Replies: 3
    Last Post: April 23rd, 2010, 03:10 PM