read byte loops infinitely when system in

Updated on science 2024-02-09
9 answers
  1. Anonymous users2024-02-05

    while((len=!=-1) Here will get the data entered by the keyboard, it is a blocking method, len will return the maximum data byte value, if the loop is no data, it will return -1, you enter does not mean that the data is over, you enter is actually it''''This means that the data has not been fetched, and the loop will continue, and then it will go to the read() method, and continue to enter, and if you want to end, you must define the end mark.

    string value = new string(buf,0,len);

    if("over".equals(value)) ends if you enter over.

    break;

    If you want to enter it once, you don't need to judge, just add break to the last hop statement of the while loop;

    while((len=!=-1)

    string(buf,0,len));

    break;

  2. Anonymous users2024-02-04

    Because your cycle end condition has always been true.

  3. Anonymous users2024-02-03

    If you don't type anything, you will get len =2;yes, so len <=2 means nothing was entered. There may be a problem with this source code.

  4. Anonymous users2024-02-02

    There are two bytes per character, so if you < 2, you don't have it at all.

  5. Anonymous users2024-02-01

    public class test

    You set the size of the byte array based on the size of the string you want to enter.

  6. Anonymous users2024-01-31

    Public int read(byte b) is a method of reading up to bytes of data from this input stream into a byte array.

    That is, when it returns -1, the data has been copied, and the while loop terminates the program.

  7. Anonymous users2024-01-30

    This is to read the number in a file and store it in bytes, and then assign a value to len for each bytes separately. If there is still a value, then len is not equal to -1, and the reading will continue in a loop until the value is read.

  8. Anonymous users2024-01-29

    The number of bytes is returned, and a Chinese character is two bytes.

  9. Anonymous users2024-01-28

    is the number of bytes returned, and it is also a Chinese character that accounts for two bytes. What question would you like to ask?

Related questions
6 answers2024-02-09

Song Title: The Earth Is Weeping.

Singer: Liu Genghong. >>>More

5 answers2024-02-09

Beethoven, a world-famous ** artist, finally composed a symphony after going through many tribulations.

2 answers2024-02-09

The lingering song spread throughout the carriage and through the windows to every corner of the world, the flower of friendship bloomed in the hearts of every listener, and the whole world became quiet and serene, without the noise and irritability of the past, only a beautiful sound, which made the white clouds stop floating, Birdchester stepped on the train to Connecticut, and at this moment his mind suddenly flashed to the picture of living with Tucker, Mario and Harry, how happy they were, Mario smiled and sold newspapers to every customer, Tucker lay on Harry's back, Harry's tail swaying comfortably, and they ate crumbled bread and drank Coke, looking like they were enjoying themselves, while Chester listened to the recording, closed his eyes and wandered in ......the ocean of human beingsYes, Chester began to regret it, but it also longed for a free life in the country, and when the train started, even regretting it would not help. Chester was surprised to see Mario, Tucker, and Harry out the window, and they waved to Chester, who, like them, had tears in his eyes. >>>More

26 answers2024-02-09

There is a saying that people will see people's hearts over time. >>>More

11 answers2024-02-09

Loosen the soil and decompose some organic matter.