I made a test program that could write to a file is already named, so I'm assuming there's some sort of problem with how this asks for a file name to create it to.
My guess is that you can't see them in the Eclipse browser because the only files that will show up in there are the ones you have imported and the newly created file won't be imported. Check your program files folder where you run Eclipse from.
Hope that helps.
Bob Sanders wrote:Fixed, sorry I didn't expect my name to show up. Can someone look at my original post though?
I can't tell from your code what file it is supposed to be writing to. And neither can you, because it depends on input from the user. So how about sticking in a line of debugging code which tells you what it is? You might be surprised.
And like Itzhok suggests, it helps if you know what your current working directory is when you run the code.
To reiterate: It's not a problem with finding or creating the file, its with writing to it once its already created.
is that line the culprit? shouldn't it just be PrintWriter output0 = new PrintWriter(outputFileName);
the code for mine begins....
public class Lab8
public static void main(String args) throws IOException
//gather input and output file names from user
//and prepare input file scanner and printwriter
Scanner kbd = new Scanner(System.in);
System.out.println("Name of input file: ");
String inFileName = kbd.nextLine();
File inputFile = new File(inFileName);
Scanner input = new Scanner(inputFile);
System.out.println("Name of output file: ");
String outFileName = kbd.nextLine();
PrintWriter output = new PrintWriter(outFileName);
and with that, I am able to go about the rest of the lab, writing to the output file with...
Bob Sanders wrote:To reiterate: It's not a problem with finding or creating the file, its with writing to it once its already created.
Suit yourself then. From my point of view I can tell that your code writes to the file, unless an exception is thrown. I just can't tell what file it writes to or where it is, so that's where I would start looking.
...is being written to the created file.
I tried changing it to output without HTML, just straight text....
Not sure if it has anything to do with it or not, but the code is also not terminating after it runs through?
And yeah thats as far as I can determine with whats happening, thanks for explaining it.
Bob Sanders wrote:Okay I've come to the conclusion that if I exclude the for loop it'll print out everything else, so for some reason the for loop is causing it not to work. Any ideas?
So: printing is working okay sometimes. No problem creating or finding the output file then. But if you broke it by inserting some more printing code, that suggests to me that the new code threw an exception. I would have thought you would notice that, though, you get the stack trace in red in your console windows and that's rather hard to miss. That goes against the exception-throwing theory, then. But since you're using Eclipse, why not just step through it in debug mode and find out what happens?