Results 1 to 5 of 5

Thread: plz help

  1. #1
    Join Date
    Feb 2011
    Posts
    14
    Rep Power
    0

    Question plz help

    hai....
    i wanna write the integers into a file... bt i culd not do it using dataoutputstream...plz check wat are the changes i need to do in my coding...

    coding:

    import java.io.DataOutputStream;
    import java.io.FileOutputStream;
    import java.io.IOException;
    import java.io.*;
    public class writeint
    {
    public static void main(String[] args) throws Exception
    {

    try
    {
    File file=new File("d:\\write.txt");
    FileOutputStream fos = new FileOutputStream(file);
    DataOutputStream dos = new DataOutputStream(fos);
    int i = 100;
    dos.writeInt(2333);
    dos.writeChars("hello");
    dos.close();
    }
    catch (IOException e)
    {
    System.out.println("IOException : " + e);
    }
    }
    }


    output is:

     h e l l o

  2. #2
    rp181 is offline Member
    Join Date
    Mar 2009
    Posts
    70
    Rep Power
    0

    Default

    Put a e.printStackTrace(); in your catch statement.

    This might be simply shows the int as characters in the ASCII. Have you tried reading it back in and displaying it? Not all writers are human readable. For human readability, I always use PrintWriter.

  3. #3
    Join Date
    Feb 2011
    Posts
    14
    Rep Power
    0

    Default

    ya it is printing ascii characters 4 certain integers........ how to overcome dis?

  4. #4
    quad64bit's Avatar
    quad64bit is offline Moderator
    Join Date
    Jul 2009
    Location
    VA
    Posts
    1,323
    Rep Power
    7

    Default

    And my answer for you on your other post on the same topic wasn't clear enough?
    Dataoutputstream

    Double Post: Dataoutputstream

  5. #5
    Fubarable's Avatar
    Fubarable is offline Moderator
    Join Date
    Jun 2008
    Posts
    19,316
    Blog Entries
    1
    Rep Power
    26

Posting Permissions

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