• Post Reply Bookmark Topic Watch Topic
  • New Topic

Need Help Attempting Printing To A Text File  RSS feed

 
Andrew Pavel
Greenhorn
Posts: 4
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Hello my current project of mine is to prompt the user to type in a certain url in which the program copies all of the url's data and pastes it in a text file however I can't seem to have the program paste any of the data to a text file.

 
Paul Clapham
Sheriff
Posts: 22841
43
Eclipse IDE Firefox Browser MySQL Database
  • Likes 1
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
That's because line 42 writes the data to the console and not to the text file. There's no code in what you posted which writes anything to the text file. (If you name the variable referring to the text file something other than "out" then your confusion would be more obvious.)

And welcome to the ranch!
 
Andrew Pavel
Greenhorn
Posts: 4
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Thanks for the welcome and the help! I see what you mean about the line 42 however if I were to make changes like this:



Adding in the pw.printf, I still don't get the data completely written down on the text file instead I get a "</html>" as the first line and nothing else.
 
Paul Clapham
Sheriff
Posts: 22841
43
Eclipse IDE Firefox Browser MySQL Database
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
For each line in the input you create a new version of the file, replacing the old version. Accordingly the last version of the file contains only the last line of the input.
 
Andrew Pavel
Greenhorn
Posts: 4
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Oh... duh. Haha! Thanks for the help I completely glossed over the whole while loop. Thanks again!

EDIT: How would I even optimize the while loop? To make the original intended work?
 
Paul Clapham
Sheriff
Posts: 22841
43
Eclipse IDE Firefox Browser MySQL Database
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Here's a brief summary of what you want:

1. Open the file.

2. Copy the data to it.

3. Close the file.

So that's different than what you have there, right? I wouldn't call it "optimizing" to change your code to do the right thing, "optimizing" means taking something which already works and making it work better, but at any rate you do need to change your code.
 
Andrew Pavel
Greenhorn
Posts: 4
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Sorry for using the wrong term, the project's intentions were to copy all raw data from the website and paste it to the text file however that while loop creates a massive problem because it overwrites the code. At this moment I have absolutely no idea how to even fix the while loop so that the code can write to the text file until the end of the raw data.
 
Carey Brown
Saloon Keeper
Posts: 3329
46
Eclipse IDE Firefox Browser Java MySQL Database VI Editor Windows
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
A program executes statements in the order they're given. You have
  • start loop
  • read data
  • open file
  • write data to file
  • close file
  • repeat loop

  • Each time you open file it wipes out any previous content.
    How would you reorder these steps differently?
     
    • Post Reply Bookmark Topic Watch Topic
    • New Topic
    Boost this thread!