正在加载图片...
Propagation Approach r Add the phrase throws <Exception to the declaration for a method that includes a call to a statement that can throw exceptions. Replace <Exception> with the actual exception class, such as IOException EoFException and so forth void computeSum (String fileName throws IOException File inFile new File(fileName )i FileInputstream inFileStream new FileInputstream(inFile) DataInput stream inDataStream new DataInputstream(inFilestream)i //read three integers int i inDatastream. readIntoi int 3= inDataStream readInt ()i int k inDatastream. readInt oi surn inDataStream. close() C 2000 McGraw-Hill troduction to Object-Oriented Programming with Java--Wu Chapter 11-14© 2000 McGraw-Hill Introduction to Object-Oriented Programming with Java--Wu Chapter 11 - 14 Propagation Approach Add the phrase throws <Exception> to the declaration for a method that includes a call to a statement that can throw exceptions. Replace <Exception> with the actual exception class, such as IOException, EOFException, and so forth. void computeSum (String fileName ) throws IOException { File inFile = new File(fileName); FileInputStream inFileStream = new FileInputStream(inFile); DataInputStream inDataStream = new DataInputStream(inFileStream); //read three integers int i = inDataStream.readInt(); int j = inDataStream.readInt(); int k = inDataStream.readInt(); sum = i + j + k; inDataStream.close(); }
<<向上翻页向下翻页>>
©2008-现在 cucdc.com 高等教育资讯网 版权所有