Results 1 to 1 of 1
  1. #1
    gotenks05 is offline Member
    Join Date
    Sep 2008
    Posts
    34
    Rep Power
    0

    Default [SOLVED] Java not fill in all info for text file

    I am making a program that creates an OPML file based on user input, but I am running into troubles and I cannot figure out what is wrong. The program compiles fine, but the error occurs at runtime. Yes, I know that runtime errors are different from syntax errors. The problem is that I have a "for" loop that enters in the outline element with the text, htmlUrl, and xmlUrl attributes that takes data from three different arrays. At runtime, everything seems to work how it should, but the text attribute is always empty.

    Java Code:
    import java.io.*;
    import java.util.*;
    
    public class CreateOPML
    {
    	public static void main(String[] args) throws IOException
    	{
    		String feed[], title, html[], xml[], file;
    		int feeds, num;
    		Scanner keyboard = new Scanner(System.in);
    		
    
    		System.out.print("Enter the number of feeds to be listed:  ");
    
    		feeds = keyboard.nextInt();
    
    		feed = new String[feeds];
    
    		html = new String[feeds];
    		xml = new String[feeds];
    
    		for (int count = 0; count <= feeds -1; count++)
    		{
    
    			System.out.print("Enter name for feed:  ");
    			feed[count] = keyboard.nextLine();
    
    			keyboard.nextLine();
    
    			System.out.print("Enter feed URL:  ");
    			xml[count] = keyboard.nextLine();
    
    			System.out.print("Enter website for feed:  ");
    			html[count] = keyboard.nextLine();
    
    			
    		}
    
    		System.out.print("Enter a title for the feed list:  ");
    		title = keyboard.nextLine();
    
    		file = title + ".opml";
    
    		FileWriter output = new FileWriter(file, true);
    
    			output.write("<opml version=\"1.0\">\n");
    			output.write("<head>\n");
    			output.write("<title>" + title + "</title>\n");
    			output.write("</head>\n");
    			output.write("<body>\n");
    
    		for (int number = 0; number <= feeds -1; number++)
    		{
    			output.write("<outline text=\"" + feed[number] + "\" " + "htmlUrl=\"" + html[number] +"\" " + "type=\"rss\" " + "xmlUrl=\"" + xml[number] + "\"" + " />\n");
    		}
    			output.write("</body>\n");
    			output.write("</opml>");
    
    			output.close();
    	}
    }
    I use the nextLine() method because the next() method stops at whitespace. Also, I cannot enter in all the data, unless I use
    Java Code:
    keyboard.nextLine();
    However, if I use it more than once, every input request after that particular input will not show up, thus the file will not be generated. How can I fix this?

    Update: Never mind, I changed out when the name of the file was asked then I changed to method used on xml[] and html[] to next() from nextLine() and it worked.
    Last edited by gotenks05; 05-25-2009 at 04:43 AM. Reason: solved

Similar Threads

  1. Replies: 9
    Last Post: 09-11-2008, 03:51 AM
  2. Replies: 5
    Last Post: 07-30-2008, 10:30 AM
  3. How to Fill Arc in Java
    By Java Tip in forum java.awt
    Replies: 0
    Last Post: 06-24-2008, 12:14 AM
  4. How to read a text file from a Java Archive File
    By Java Tip in forum Java Tip
    Replies: 0
    Last Post: 02-08-2008, 10:13 AM
  5. Converting text file(.txt) to JPG file(.jpg) in java
    By javadeveloper in forum Advanced Java
    Replies: 0
    Last Post: 11-09-2007, 05:22 PM

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •