Results 1 to 3 of 3

Thread: output streams

  1. #1

    Thread Starter
    Lively Member
    Join Date
    Mar 2001
    Location
    Massachusetts, USA
    Posts
    111

    output streams

    I am trying to write numbers to a text file. i have tried most of the classes in java.io but whenever i write a number to a file it comes up as jibberish. anyone know what class to use?

  2. #2

  3. #3
    The Devil crptcblade's Avatar
    Join Date
    Aug 2000
    Location
    Quetzalshacatenango
    Posts
    9,091
    I would do this :
    Code:
    import java.io.*;
    
    public class WriteIntToFile
    {
        public static void main(String[] args)
        {
            PrintWriter pw = new PrintWriter(new FileWriter("c:\\test.txt",true), true); //FileWriter:true = append, PrintWriter:true = autoflush
       
            for (int x=0; x<10; x++)
            {
                pw.println(x);
            }
    
            pw.close();
        }
    }
    that should do it

    Laugh, and the world laughs with you. Cry, and you just water down your vodka.


    Take credit, not responsibility

Posting Permissions

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



Click Here to Expand Forum to Full Width