我正在尝试测试一个程序,为此我需要访问ReadExternal函数,但我在ObjectInputStream上得到StreamCorrupted异常.我知道我需要使用WriteObject编写的对象,但不知道该怎么做...
ObjectOutputStream out=new ObjectOutputStream(new ByteArrayOutputStream());
out.writeObject(ss3);
ss3.writeExternal(out);
try{
ByteInputStream bi=new ByteInputStream();
bi.setBuf(bb);
out.write(bb);
ObjectInputStream in = new ObjectInputStream(new ByteArrayInputStream(bb));
String s1=(String) in.readObject();
}
catch(Exception e){
e.printStackTrace();
}
Run Code Online (Sandbox Code Playgroud) 我编写了以下程序和程序抛出编译错误
我不知道为什么会出现错误,因为所有的分号和括号似乎都已到位
import java.io.*;
public class Solution {
public static void main(String args[]) throws Exception {
long coords[5000][2];
long number;
BufferedReader br = new BufferedReader(new InputStreamReader(System.in));
try {
number = Long.parseLong(br.readline()); // take no of inputs
//take all co ordinates and store it in 2d array
for(long i=0;i<number;i++) {
coords[i][0] = Long.parseLong(br.readline());
coords[i][1] = Long.parseLong(br.readline());
}
} catch(NumberFormatException e) {
System.out.println("Number Format Exception:");
}
if(check_line(coords,number)) {
System.out.println("YES");
} else {
System.out.println("NO");
}
}
public boolean check_line(long coords[][], long limit) { …Run Code Online (Sandbox Code Playgroud) java ×2