gpt4 book ai didi

java - 尝试没有捕获错误

转载 作者:行者123 更新时间:2023-12-02 11:09:12 25 4
gpt4 key购买 nike

我正在编写一个程序来处理序列化文件。我收到错误消息,说我的openObjectInputStreamMethod中有尝试,但没有成功。事情是我既有尝试又有这种方法。其他一切似乎都正常。任何帮助都会很棒。

  public static ObjectInputStream openObjectInputStream( String fileName )
throws IOException
{
/*
* This is a generic open method for an ObjectInputStream.
* Using the received String value (containing a file name), this method should
* create a new ObjectInputStream and return the reference to the newly
* instantiated ObjectInputStream to the calling method.
*/
try
{
inAccount = new ObjectInputStream(
Files.newInputStream(
Paths.get("NewAccounts.ser" ) ) ) ;
return new ObjectInputStream // complete this statement.

} // end try block
catch( IOException openError )
{
System.err.printf( "%nError opening %s", fileName ); // output an alert
// rethrow/chain exception to be caught in main
throw new IOException( String.format( "Error opening %s", fileName ), openError );
}
} // end openObjectInputStream


public static void closeObjectInputStream( ObjectInputStream ObjInStream )
{
/*
* This is a generic close method for an ObjectInputStream.
* Using the instantiated ObjectInputStream object, this method will close that object
*/
try
{
// The ObjectInputStream object will be null only if it was never successfully opened
if ( ObjInStream != null )
ObjInStream.close();
}
catch( IOException closeError )
{
System.err.printf( "%nError closing %s", ObjInStream );
}
} // end closeObjectInputStream

最佳答案

以下行缺少分号(即使这样也不正确):

return new ObjectInputStream  // complete this statement.

无法看到您的其余代码,也许应该是:
return inAccount;  // complete this statement.

关于java - 尝试没有捕获错误,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/33907257/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com