Welcome to the Java Programming Forums


The professional, friendly Java community. 21,500 members and growing!


The Java Programming Forums are a community of Java programmers from all around the World. Our members have a wide range of skills and they all have one thing in common: A passion to learn and code Java. We invite beginner Java programmers right through to Java professionals to post here and share your knowledge. Become a part of the community, help others, expand your knowledge of Java and enjoy talking with like minded people. Registration is quick and best of all free. We look forward to meeting you.


>> REGISTER NOW TO START POSTING


Members have full access to the forums. Advertisements are removed for registered users.

Results 1 to 3 of 3

Thread: Output an int i to a file

  1. #1
    Junior Member
    Join Date
    Apr 2010
    Posts
    5
    Thanks
    0
    Thanked 0 Times in 0 Posts

    Default Output an int i to a file

    The Question is as follows: Explain the difference between the output of the following two fragments of code for outputting an int i to a file

    i)

    PrintWriter outfile = new PrintWriter(new FileWriter("ints.txt"));
    outfile.print(i);

    ii)

    DataOutputStream out = new DataOutputStream(new FileOutputStream("ints.dat"));
    out.writeInt(i);

    I believe the PrintWriter coverts the stream into Unicode and the DataOutStream converts higher level data items to sequence of bytes.

    What more can be said?


  2. #2
    Super Moderator Norm's Avatar
    Join Date
    May 2010
    Location
    Eastern Florida
    Posts
    25,140
    Thanks
    65
    Thanked 2,720 Times in 2,670 Posts

    Default Re: Output an int i to a file

    the difference between the output
    Have you tried executing the two segments?
    What do they output? Can you copy and paste the output here to show us?
    Use a hexeditor if needed.

  3. #3
    Super Moderator helloworld922's Avatar
    Join Date
    Jun 2009
    Posts
    2,895
    Thanks
    23
    Thanked 619 Times in 561 Posts
    Blog Entries
    18

    Default Re: Output an int i to a file

    For your section segment, you can talk about serialization, other than that do what norm said and run the code

Similar Threads

  1. Why am I getting this output?
    By ptabatt in forum What's Wrong With My Code?
    Replies: 5
    Last Post: August 6th, 2010, 07:36 PM
  2. need help with output.
    By VictorCampudoni in forum What's Wrong With My Code?
    Replies: 0
    Last Post: June 24th, 2010, 11:25 PM
  3. Writing Output To New File
    By Scottj996 in forum File I/O & Other I/O Streams
    Replies: 1
    Last Post: January 6th, 2010, 07:25 PM
  4. OutPut.
    By chronoz13 in forum Java Theory & Questions
    Replies: 3
    Last Post: August 29th, 2009, 10:54 AM
  5. printing output to console & to a text file at the same time...
    By prasanna in forum File I/O & Other I/O Streams
    Replies: 3
    Last Post: August 26th, 2009, 03:43 AM