ObjectInputStream 類的 skipBytes() 方法用於通過作為參數傳遞的數字跳過字節。
用法
public int skipBytes(int len) throws IOException
參數
len 作為要跳過的字節數
返回
實際跳過的字節數。
拋出
IOException
例子1
import java.io.*;
public class ObjectInputStreamreadunskipByteExample1 {
public static void main(String[] args) {
String s = "javaTpoint";
try {
FileOutputStream outstream = new FileOutputStream("file1.txt");
ObjectOutputStream objoutstream = new ObjectOutputStream(outstream);
objoutstream.writeUTF(s);
objoutstream.writeUTF("javaTpoint provide tutorial for all languages");
objoutstream.flush();
ObjectInputStream objinstream = new ObjectInputStream(new FileInputStream("file1.txt"));
objinstream.skipBytes(6);
for (int i = 0; i < objinstream.available() - 6; i++) {
System.out.print("" + (char) objinstream.readByte());
}
} catch (Exception ex) {
ex.printStackTrace();
}
}
}
輸出:
Tpoint javaTpoint provide
例子2
import java.io.*;
public class ObjectInputStreamreadunskipByteExample2
{
public static void main(String[] args) throws IOException, ClassNotFoundException
{
FileOutputStream outstream = new FileOutputStream("file1.txt");
ObjectOutputStream objoutStream = new ObjectOutputStream(outstream);
ObjectInputStream objinStream = new ObjectInputStream(new FileInputStream("file1.txt"));
objoutStream.writeUTF(" Welcome to javatpoint");
objoutStream.flush();
objinStream.skipBytes(7);
for (int i = 2; i < objinStream.available(); i++)
{
System.out.print((char) objinStream.readByte());
}
}
}
輸出:
ome to j
相關用法
- Java Objectinputstream readUnsignedShort()用法及代碼示例
- Java ObjectInputStream readDouble()用法及代碼示例
- Java ObjectStreamField getOffset()用法及代碼示例
- Java ObjectStreamField compareTo()用法及代碼示例
- Java Object hashCode()用法及代碼示例
- Java ObjectInputStream readUnsignedByte()用法及代碼示例
- Java ObjectInputStream readFields()用法及代碼示例
- Java ObjectOutputStream writeFields()用法及代碼示例
- Java ObjectInputStream readFully()用法及代碼示例
- Java ObjectStreamField getName()用法及代碼示例
- Java ObjectInputStream readInt()用法及代碼示例
- Java ObjectStreamClass forClass()用法及代碼示例
- Java ObjectInputStream read()用法及代碼示例
- Java ObjectStreamField getTypeCode()用法及代碼示例
- Java ObjectOutputStream writeBytes()用法及代碼示例
- Java ObjectInputStream readUTF()用法及代碼示例
- Java Object equals(Object obj)用法及代碼示例
- Java ObjectInputStream close()用法及代碼示例
- Java ObjectOutputStream useProtocolVersion()用法及代碼示例
- Java ObjectStreamClass getSerialVersionUID()用法及代碼示例
注:本文由純淨天空篩選整理自 Java Objectinputstream skipBytes() Method。非經特殊聲明,原始代碼版權歸原作者所有,本譯文未經允許或授權,請勿轉載或複製。