• Post Reply Bookmark Topic Watch Topic
  • New Topic

New Text File Creation Problem  RSS feed

 
Paul Peterson
Ranch Hand
Posts: 106
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Who ever said there is no such thing as a stupid question never met me.

I know I'm missing something simple, but not sure what. When running the following I have to enter the name of the output file twice. Hopefully someone has a flashlight to shine some light on this.

Thank you in advance.

 
Knute Snortum
Sheriff
Posts: 4279
127
Chrome Eclipse IDE Java Postgres Database VI Editor
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
java.util.Sanner.next() really shouldn't be used much. It doesn't "consume" the new line character at the end of the input. Try java.util.Sanner.nextline()
 
Campbell Ritchie
Marshal
Posts: 56546
172
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
You are asking for the name of the output file twice. Once on line 50 and once on line 55. I am a bit surprised your do loop ever stops, considering what you have put as its repetition condition.
 
Campbell Ritchie
Marshal
Posts: 56546
172
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Knute Snortum wrote:java.util.Scanner.next() really shouldn't be used much. . . .
Nothing wrong with using Scanner#next. You may get problems if you use nextLine after next, however.
 
Knute Snortum
Sheriff
Posts: 4279
127
Chrome Eclipse IDE Java Postgres Database VI Editor
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Really? Did I get it backwards?
 
Paul Peterson
Ranch Hand
Posts: 106
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Campbell Ritchie wrote:You are asking for the name of the output file twice. Once on line 50 and once on line 55. I am a bit surprised your do loop ever stops, considering what you have put as its repetition condition.


Thank you.
 
Campbell Ritchie
Marshal
Posts: 56546
172
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Knute Snortum wrote:Really? Did I get it backwards?
I think you did, I am afraid.
 
Campbell Ritchie
Marshal
Posts: 56546
172
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
I think your output file does not exist. Try writing to it and then see whether it exists. It is not usual to ask the name twice; do it this way:-Read about the try without a close() invocation in the Java® Tutorials. Note the %n tag adds line end characters automatically.

Alternative:-Look in the Java® Tutorials and find about the new IO classes introduced in 2011.
 
  • Post Reply Bookmark Topic Watch Topic
  • New Topic
Boost this thread!