creating a text file


DevX Home    Today's Headlines   Articles Archive   Tip Bank   Forums   

Results 1 to 3 of 3

Thread: creating a text file

Hybrid View

  1. #1
    Join Date
    Dec 2007
    Posts
    9

    creating a text file

    hi all
    can anyone tell me how to create a text file, naming it and writing it using java...

  2. #2
    Join Date
    Dec 2004
    Location
    San Bernardino County, California
    Posts
    1,468
    There is not an easy answer to this because only you know the functionality you need for your file. The basic components are a file object, a stream, and a reader/writer for the stream.

    Take a look at the Java Tutorial section on basic Input/Output starting at
    http://java.sun.com/docs/books/tutorial/essential/io/

  3. #3
    Join Date
    Dec 2005
    Posts
    48
    Give you a sample, hope it helps to you.
    import java.io.InputStream;
    import java.io.OutputStream;
    import java.io.FileInputStream;
    import java.io.FileOutputStream;

    public class FileInputOutputExample
    {
    public static void main( String[] args ) {
    try {
    InputStream is = new FileInputStream( "input.txt" );
    OutputStream os = new FileOutputStream( "output.txt" );
    int c;
    while( ( c = is.read() ) != -1 ) {
    System.out.print( ( char )c );
    os.write( c );
    }
    is.close();
    os.close(); }
    catch( Exception e ) {
    e.printStackTrace();
    }
    }
    }

Similar Threads

  1. writing to a text file
    By persian_celina in forum .NET
    Replies: 0
    Last Post: 02-19-2006, 02:06 AM
  2. Importing text file using schema.ini
    By Kevin in forum VB Classic
    Replies: 3
    Last Post: 12-05-2005, 06:25 PM
  3. Replies: 0
    Last Post: 08-08-2002, 05:56 AM
  4. Replies: 0
    Last Post: 09-02-2000, 08:18 PM
  5. Replies: 0
    Last Post: 04-17-2000, 01:33 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
  •  
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