File IO Compiles, but wont work?
I wrote this code and compiled it in eclipse I have a text file hello.txt in the same src folder as the .class it does compile properly but wont append the Dirk Benson to the file I have no idea what is wrong.
Code Java:
import java.io.*;
public class ioappend
{
/**
* @param args
*/
public static void main(String[] args) throws IOException
//TODO make try/catch for in-thread error catching
{
String filename;
BufferedReader input = new BufferedReader
( new InputStreamReader(System.in));//TODO testing only
System.out.println("Enter a file name: ");//TODO testing only
filename = input.readLine();//TODO testing only
FileWriter inject = new FileWriter( filename, true);
inject.write("Dirk Benson");
inject.close();
}
}
Re: File IO Compiles, but wont work?
Are any exceptions thrown when you run it? Where is the file you want to append, and what do you enter?
Re: File IO Compiles, but wont work?
the file I want to append to is in the same package as the .class file, hello.txt. I want to simply append some string of text I put dirk benson in there for right now. Thanks
I did a try catch block no errors shown
Re: File IO Compiles, but wont work?
I compiled your code its running absolutely fine.
appending the content.
Re: File IO Compiles, but wont work?
Hello StarKannon.
I have tested this code and it works fine.
Try putting the hello.txt file in the package folder. The same location as the src and bin folders.
Re: File IO Compiles, but wont work?
Quote:
Try putting the hello.txt file in the package folder. The same location as the src and bin folders.
if your file hello.txt is in another location , specify the absolute path to that file.