Results 1 to 3 of 3
  1. #1
    Johnson is offline Member
    Join Date
    May 2011
    Posts
    1
    Rep Power
    0

    Default how to print text file

    I'm new to Java.

    I want to print the items list to the text file, such as:

    10001 harddisk
    10002 monitor

    to stocklist.txt

    how can I do it?

    thanks for the help.

  2. #2
    KevinWorkman's Avatar
    KevinWorkman is offline Crazy Cat Lady
    Join Date
    Oct 2010
    Location
    Washington, DC
    Posts
    3,939
    Rep Power
    8

    Default

    How to Ask Questions the Smart Way
    Static Void Games - Play indie games, learn from game tutorials and source code, upload your own games!

  3. #3
    Solarsonic is offline Senior Member
    Join Date
    Mar 2011
    Posts
    261
    Rep Power
    4

    Default

    Use the BufferedWriter class.

    Java Code:
    File f = new File("example.txt");
    BufferedWriter bw = new BufferedWriter(new FileWriter(f));
    Is the item list an array or an array list? If so, you can dot his with your new Buffered Writer:

    Java Code:
    for(String s : array){
    bw.write(s);
    bw.newLine();
    }

Similar Threads

  1. Text file into an array then Print
    By Mrussell9 in forum New To Java
    Replies: 0
    Last Post: 05-06-2011, 01:28 PM
  2. Read, Edit, and Print text file
    By maddmike71 in forum New To Java
    Replies: 0
    Last Post: 02-23-2011, 01:18 AM
  3. trying to print a text file.
    By IYIaster in forum New To Java
    Replies: 1
    Last Post: 10-12-2009, 06:55 PM
  4. Replies: 6
    Last Post: 04-09-2009, 02:11 AM
  5. Print the text file and print preview them
    By Java Tip in forum java.awt
    Replies: 0
    Last Post: 06-22-2008, 11:04 PM

Posting Permissions

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