How can i write the string value to a text file ?
I try to use FileWriter but it return me error.
Please help.
Printable View
How can i write the string value to a text file ?
I try to use FileWriter but it return me error.
Please help.
Hi,
What does the error say?
You can write a string value to a text file like this:
FileWriter writer = new FileWriter("test.txt");
writer.write("this is a test file");
writer.close();
If you try this, what error do you get?
Regards,
Geert Arys
Error program below.. pls help ..
import java.io.*;
public class FileWriterTest
{
FileWriter famex = new FileWriter("amex.txt");
famex.write("Success write into text file");
famex.close();
}
********** Error code ************
FileWriterTest.java6: Type Expected
famex.write("Success write into text file");
^
********** End Error code ************
> public class FileWriterTest
> {
> FileWriter famex = new FileWriter("amex.txt");
> famex.write("Success write into text file");
> famex.close();
> }
Where is the function ???? Shouldnt those 3 lines be inside a function ????
this the full code .. what is wrong ?
***************
import java.io.FileWriter;
class FileWriterTest
{
public static void main(String[] args)
{
FileWriter fwriter = new FileWriter("Amex.txt");
fwriter.write("testing");
fwriter.close();;
}
}
***************
Hi
Try this. It works. You had not catched the exception..
import java.io.FileWriter;
class FileWriterTest
{
public static void main(String[] args)
{
try
{
FileWriter fwriter = new FileWriter("Amex.txt");
fwriter.write("testing");
fwriter.close();;
}
catch(Exception e){}
}
}