Ask Experts Questions for FREE Help !
Ask
    dhaval2711's Avatar
    dhaval2711 Posts: 1, Reputation: 1
    New Member
     
    #1

    Apr 22, 2013, 10:33 PM
    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)
    {
    }
    }
    }
    rameshspry's Avatar
    rameshspry Posts: 4, Reputation: 1
    New Member
     
    #2

    Jul 4, 2013, 11:40 PM
    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());
    }
    }
    }

Not your question? Ask your question View similar questions

 

Question Tools Search this Question
Search this Question:

Advanced Search

Add your answer here.


Check out some similar questions!

Writing SQL query output into text files of configsize (shell script & MySQL code at) [ 0 Answers ]

In the application requirement, the current and required funcationality are as follows:- Current scenario:- (I)A MySQL stored proc is called from the shell script as given in below code. (ii)The procedure generates the transaction dump file by querying the relevant table And using the syntax...

To get higher wattage output in a lower output fixture. [ 1 Answers ]

We purchased a Harbor Breeze fan with light fixture, but did not see that the wattage output was only going to be 40 watts. We need more lighting in our room. We have tried bigger watt bulbs but the fixture starts to blink and then goes dim(back to the 40 watt output). How can we change that?

Code Segment Output for C++ [ 9 Answers ]

To anyone who can help. I am in the beginning stages of C++ and I need some help with the following question. Don't just give me the answer if you can, please explained how to determine out. Thanks. What is the output of the following code segment? for(int m=1; m <= 4; m++) cout <<...


View more questions Search