Ask Me Help Desk

Ask Me Help Desk (https://www.askmehelpdesk.com/forum.php)
-   Java (https://www.askmehelpdesk.com/forumdisplay.php?f=440)
-   -   Why output is not 121212 in following java code but the output is |||? (https://www.askmehelpdesk.com/showthread.php?t=745557)

  • Apr 22, 2013, 10:33 PM
    dhaval2711
    Why output is not 121212 in following java code but the output is |||?
    please help in following java code, I have to write 121212 ten times in poll.txt file but when I open poll.txt file it shows me |||||||||| output

    import java.io.*;
    class Byte{
    public static void main(String args[]) throws IOException {
    try{FileOutputStream f=new FileOutputStream("poll.txt");
    for(int I=0;i<10;i++)
    f.write(121212);
    f.close();
    }catch(Exception e)
    {
    }
    }
    }
  • Jul 4, 2013, 11:40 PM
    rameshspry
    To write the content into the file
    we need to convert the content into the byte.

    Like this...



    import java.io.*;
    class Byte
    {
    public static void main(String args[]) throws IOException
    {
    String content="121212";
    try
    {
    FileOutputStream f=new FileOutputStream("poll.txt");
    for(int I=0;i<10;i++)
    {
    byte[] contentInBytes = content.getBytes();
    f.write(contentInBytes);

    }
    f.close();

    }
    catch(Exception e)
    {
    System.out.println(e.toString());
    }
    }
    }

  • All times are GMT -7. The time now is 10:31 AM.