正在加载图片...
try-catch Approach r Use the try-catch statement to include the exception handling routines void compute Sum (String fileName success true try t File inFile new File(fileName FileInput stream inFileStream new FileInputstream(inFile) DataInput stream inDataStream new DataInputstream(inFilestream)i //read three integers int i inDataStream. readIntoi int j= inDatastream readInt( int k inDataStream readInt()i sum =1 +3 + ki inDatastream. close catch (IOException e) t success false C 2000 McGraw-Hill Introduction to Object-Oriented Programming with Java--Wu Chapter 11-15© 2000 McGraw-Hill Introduction to Object-Oriented Programming with Java--Wu Chapter 11 - 15 try-catch Approach Use the try-catch statement to include the exception￾handling routines. void computeSum (String fileName ) { success = true; try { 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(); } catch (IOException e) { success = false; } }
<<向上翻页向下翻页>>
©2008-现在 cucdc.com 高等教育资讯网 版权所有