Results 1 to 1 of 1
- 05-24-2009, 05:17 PM #1
Member
- Join Date
- Sep 2008
- Posts
- 34
- Rep Power
- 0
[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.
I use the nextLine() method because the next() method stops at whitespace. Also, I cannot enter in all the data, unless I useJava 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(); } }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?Java Code:keyboard.nextLine();
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 03:43 AM. Reason: solved
Similar Threads
-
Anyone know how to take info from a txt file and convert it to a char array?
By 2potatocakes in forum New To JavaReplies: 9Last Post: 09-11-2008, 02:51 AM -
How do you read from a file, and then store the info in an array?
By szimme101 in forum New To JavaReplies: 5Last Post: 07-30-2008, 09:30 AM -
How to Fill Arc in Java
By Java Tip in forum java.awtReplies: 0Last Post: 06-23-2008, 11:14 PM -
How to read a text file from a Java Archive File
By Java Tip in forum Java TipReplies: 0Last Post: 02-08-2008, 09:13 AM -
Converting text file(.txt) to JPG file(.jpg) in java
By javadeveloper in forum Advanced JavaReplies: 0Last Post: 11-09-2007, 04:22 PM


LinkBack URL
About LinkBacks
Reply With Quote
Bookmarks