String to a textfile?


DevX Home    Today's Headlines   Articles Archive   Tip Bank   Forums   

Results 1 to 3 of 3

Thread: String to a textfile?

  1. #1
    alex Guest

    String to a textfile?


    If I have a string declare like this String z ="hello"; and I want to put
    the value of 'z' into a "text.txt" in other words, I'm copying the value
    of 'z' into the "text.txt". how can I accomplish this?

    thanks in advance

  2. #2
    Adnan Zafar Guest

    Re: String to a textfile?


    Alex,

    1) Create a FileOutputStream object and pass it the filename of the output
    file as a parameter.
    2) Create a PrintWriter object and pass it the FileOutputStream as a parameter.
    3) Call the .print() (or .println()) method on the PrintWriter object you
    created and pass it your string (z) as a parameter (printWriter.print(z)).
    4) .close() your FileOutputStream.

    --
    Adnan Zafar

    "alex" <cad1374@yahoo.com> wrote:
    >
    >If I have a string declare like this String z ="hello"; and I want to put
    >the value of 'z' into a "text.txt" in other words, I'm copying the value
    >of 'z' into the "text.txt". how can I accomplish this?
    >
    >thanks in advance



  3. #3
    Selvakumar Guest

    Re: String to a textfile?


    follow the following code

    z="hello";
    FileWriter fw = new FileWriter("text.txt");
    fw.write(z);

    This code will work.

    Love
    Selva

    "alex" <cad1374@yahoo.com> wrote:
    >
    >If I have a string declare like this String z ="hello"; and I want to put
    >the value of 'z' into a "text.txt" in other words, I'm copying the value
    >of 'z' into the "text.txt". how can I accomplish this?
    >
    >thanks in advance



Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  
HTML5 Development Center
 
 
FAQ
Latest Articles
Java
.NET
XML
Database
Enterprise
Questions? Contact us.
C++
Web Development
Wireless
Latest Tips
Open Source


   Development Centers

   -- Android Development Center
   -- Cloud Development Project Center
   -- HTML5 Development Center
   -- Windows Mobile Development Center