This week's book giveaway is in the Java 8 forum.
We're giving away four copies of Java 8 in Action and have Raoul-Gabriel Urma, Mario Fusco, and Alan Mycroft on-line!
See this thread for details.
The moose likes Beginning Java and the fly likes Large blocks of white space while outputting to a file? Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login


Win a copy of Java 8 in Action this week in the Java 8 forum!
JavaRanch » Java Forums » Java » Beginning Java
Bookmark "Large blocks of white space while outputting to a file?" Watch "Large blocks of white space while outputting to a file?" New topic
Author

Large blocks of white space while outputting to a file?

jon mcgee
Greenhorn

Joined: Mar 20, 2012
Posts: 3
hi, i am working on project for school and so far the only problem i cannot figure out are these large blocks of spaces that show up in my output of my text file. The premise is to design the logic behind a maze pathfinding cowboy. If someone could look at the solve method and tell me why this is going on i would greatly appreciate it. all code besides the logic was written by my teacher just so you know.

Thanks for any input!
Paul Clapham
Bartender

Joined: Oct 14, 2005
Posts: 18165
    
    8

Hi Jon, welcome to the Ranch!

For what it's worth, I put the "Code" tags around your code, to make it more readable. However there are still two problems:

(1) There's way too much code. Nobody is going to want to dig through all of that to look for your problem.

(2) There isn't enough code. Your code breaks off right in the middle, and none of the code you did post has anything to do with writing to a file. Except the comments.

So if you want help, it would be best if you could cut the size of the program way down. Get rid of all of the code which has nothing to do with writing to the file and just post the relevant part. And next time you write a program: Don't write several hundred lines of code before you start testing it. Test it as you go along. That way finding the bugs isn't nearly as daunting.

For that matter you might want to apply that advice to this program. Start over and test the code as you write it.
jon mcgee
Greenhorn

Joined: Mar 20, 2012
Posts: 3
wow sorry about that lol i have never asked for help with code on a forum before so those tips were very helpful. i have checked all of the code i have written up to this point and everything works fine.

the only problem is the output to file is either not working, or gives me a giant text file with tons of white spaces. I know this is because our teacher wrote the array the maze is handled in to be 255x255 and all that white space is messing with the formatting of the output making the next run of the maze screwy. when i change the size of my print statement to just print for the height by width (like it is below), it doesn't output anything. this is what i have so far for the print (excuse the bad formatting i am just messing with it)

thanks again!



Paul Clapham
Bartender

Joined: Oct 14, 2005
Posts: 18165
    
    8

That looks more or less okay to me, although it's a bit hard to understand because of the inconsistent indentation.

So you say that code outputs nothing? You might find differently if you closed the writer after you were finished using it.
jon mcgee
Greenhorn

Joined: Mar 20, 2012
Posts: 3
well that fixed it, i wish one of my teachers would have taught us that at some point lol thank you a ton!
Paul Clapham
Bartender

Joined: Oct 14, 2005
Posts: 18165
    
    8

Here's the rule: when you're using a resource (anything which connects with the world outside Java, like a file or a database or a socket connection), always close it when you're finished with it. If you aren't sure whether something you're using counts as a resource, look and see if it has a "close" method. If it does, it's probably a resource.
Darryl Burke
Bartender

Joined: May 03, 2008
Posts: 4523
    
    5

Also, if the class has a dispose() method (like java.awt.Graphics) you should dispose() the object when you no longer have need of it.


luck, db
There are no new questions, but there may be new answers.
 
I agree. Here's the link: http://aspose.com/file-tools
 
subject: Large blocks of white space while outputting to a file?
 
Similar Threads
Linking internal frames with a line
wanted help in the practice program--"Cycling"
Switch Statement
a very elusive bug
How to implement the wall follower algorithm in java?