how do i write data to text file
CodeGuru Home VC++ / MFC / C++ .NET / C# Visual Basic VB Forums Developer.com
Results 1 to 6 of 6

Thread: how do i write data to text file

  1. #1
    Join Date
    Dec 1999
    Posts
    18

    how do i write data to text file

    How can i write the string value to a text file ?
    I try to use FileWriter but it return me error.

    Please help.


  2. #2
    Join Date
    Dec 2000
    Location
    Belgium
    Posts
    264

    Re: how do i write data to text file

    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

  3. #3
    Join Date
    Dec 1999
    Posts
    18

    Re: how do i write data to text file

    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 ************


  4. #4
    Join Date
    Sep 1999
    Location
    Madurai , TamilNadu , INDIA
    Posts
    1,024

    Re: how do i write data to text file


    > 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 ????



  5. #5
    Join Date
    Dec 1999
    Posts
    18

    Re: how do i write data to text file

    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();;
    }
    }
    ***************




  6. #6
    Join Date
    Jan 2001
    Location
    India
    Posts
    9

    Re: how do i write data to text file

    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){}
    }
    }




Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  


Azure Activities Information Page

Windows Mobile Development Center


Click Here to Expand Forum to Full Width

This is a CodeGuru survey question.


Featured


HTML5 Development Center