| |

VerySource

 Forgot password?
 Register
Search
View: 694|Reply: 2

Ask a simple question

[Copy link]

3

Threads

17

Posts

14.00

Credits

Newbie

Rank: 1

Credits
14.00

 China

Post time: 2020-1-24 18:20:01
| Show all posts |Read mode
char ch2 = 0;
try {
ch2 = (char) System.in.read ();
System.in.skip (2);
} catch (IOException z) {
}
What's the use of calling the sKip method here? English api description can't understand
Reply

Use magic Report

1

Threads

21

Posts

19.00

Credits

Newbie

Rank: 1

Credits
19.00

 China

Post time: 2020-2-11 20:45:01
| Show all posts
Skips over and discards n bytes of data from this input stream
-------------------------------------------------- -----------
Skip from this stream and discard N bytes of data

for example:
 
 char ch2 = (char) System.in.read ();
 System.in.skip (2);
 ch2 = (char) System.in.read ();
 ch2 = (char) System.in.read ();
 System.out.println (ch2);

Enter 12345 and press Enter
The result is 5
Reply

Use magic Report

0

Threads

6

Posts

5.00

Credits

Newbie

Rank: 1

Credits
5.00

 Great Britain

Post time: 2020-2-11 23:30:02
| Show all posts
System.in returns InputStream and then its skip method
public long skip (long n)
          throws IOException skips and discards n data bytes in this input stream. For various reasons, the skip method ends after skipping some smaller number of bytes (possibly 0). This can be caused by several conditions; reaching the end of the file before n bytes are skipped is just one of them. Returns the actual number of bytes skipped. If n is negative, no bytes are skipped.
The skip method of InputStream creates a byte array and then reads into it repeatedly until n bytes have been read or the end of the stream has been reached. It is recommended that subclasses provide a more efficient implementation of this method.


parameter:
n-the number of bytes to skip.
return:
The actual number of bytes skipped.
Throws:
IOException-if an I / O error occurs.

-------------------------------------------------- ------------------------------
Reply

Use magic Report

You have to log in before you can reply Login | Register

Points Rules

Contact us|Archive|Mobile|CopyRight © 2008-2023|verysource.com ( 京ICP备17048824号-1 )

Quick Reply To Top Return to the list