|
-
Error when reading and writing a line from a text file - any help!!
Hi,
My test main class allows user input to create one integer, which I've converted to a string, plus four strings representing details to be written to a file. When these details are written to the file they initially read correctly, eg:
111,hello one,hello two,hello three,hello four
The problem occurs when I try to write a second set if user entry values to this file. It is expecting four strings as words, and therefore reads and writes the above line as follows,
111,,hello,one,hello,two,hello,three,hello
I have absolutely no idea why this is happening and would really appreciate some help or advice with this problem.
The current code for my test main class is as follows,
Code:
import simplejava.*;
import videos.*;
import java.io.*;
public class AddTitle {
public static void main(String[] args) {
String film, actor1, actor2, director, title;
int codeNum;
SimpleReader keyboard = new SimpleReader();
SimpleWriter screen = new SimpleWriter();
SimpleReader inFile = new SimpleReader("title_test.txt");
TitleList titles = new TitleList(inFile);
codeNum = keyboard.readInt("Title Code for the Film");
int intValue = codeNum;
String stringValue = Integer.toString(intValue);
film = keyboard.readLine("Film Title?");
actor1 = keyboard.readLine("Lead Actor?");
actor2 = keyboard.readLine("Supporting Actor?");
director = keyboard.readLine("Director?");
titles.add(new Title(codeNum, film, actor1, actor2, director));
screen.println(titles);
title = inFile.readLine();
String[] myStrings = title.split(",");
for (int i=0; i<myStrings.length; i++)
System.out.print(myStrings[i]);
SimpleWriter outFile = new SimpleWriter("title_test.txt");
titles.saveTo(outFile);
outFile.close();
}
}
Does anybody know why this is happening?
Any help or advice really appreciated!!
Similar Threads
-
Replies: 1
Last Post: 11-14-2005, 04:28 PM
-
By sameera in forum VB Classic
Replies: 1
Last Post: 09-16-2005, 05:42 AM
-
By Jenks in forum VB Classic
Replies: 6
Last Post: 05-24-2005, 02:22 PM
-
By Charlie Flynn in forum Java
Replies: 3
Last Post: 08-23-2001, 11:01 AM
-
By Andrew McLellan in forum Java
Replies: 3
Last Post: 05-09-2001, 05:34 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
Forum Rules
|
Top DevX Stories
Easy Web Services with SQL Server 2005 HTTP Endpoints
JavaOne 2005: Java Platform Roadmap Focuses on Ease of Development, Sun Focuses on the "Free" in F.O.S.S.
Wed Yourself to UML with the Power of Associations
Microsoft to Add AJAX Capabilities to ASP.NET
IBM's Cloudscape Versus MySQL
|
Bookmarks