标签:== got com 技术 程序猿 基本 into 打印 注意

//假如我们要实现将一个文件读入内存,实际上真正核心只需要下面5步readFile {open the file;determine its size;allocate that much memory;read the file into memory;close the file;}
//为了处理文件不能打开、不能确定文件大小、内存分配不足等可能出现的意外,我们可能最终写成如下errorCodeType readFile {initialize errorCode = 0;open the file;if (theFileIsOpen) {determine the length of the file;if (gotTheFileLength) {allocate that much memory;if (gotEnoughMemory) {read the file into memory;if (readFailed) {errorCode = -1;}} else {errorCode = -2;}} else {errorCode = -3;}close the file;if (theFileDidntClose && errorCode == 0) {errorCode = -4;} else {errorCode = errorCode and -4;}} else {errorCode = -5;}return errorCode;}
readFile {try {open the file;determine its size;allocate that much memory;read the file into memory;close the file;} catch (fileOpenFailed) {doSomething;} catch (sizeDeterminationFailed) {doSomething;} catch (memoryAllocationFailed) {doSomething;} catch (readFailed) {doSomething;} catch (fileCloseFailed) {doSomething;}}

com.test9.MyException: 文件没有找到--02at com.test9.Test.g(Test.java:31)at com.test9.Test.main(Test.java:38)Caused by: com.test9.MyException: 文件没有找到--01at com.test9.Test.f(Test.java:22)at com.test9.Test.g(Test.java:28)... 1 moreCaused by: java.io.FileNotFoundException: G:\myfile\struts.txt (系统找不到指定的路径。)at java.io.FileInputStream.open(Native Method)at java.io.FileInputStream.<init>(FileInputStream.java:106)at java.io.FileInputStream.<init>(FileInputStream.java:66)at java.io.FileReader.<init>(FileReader.java:41)at com.test9.Test.f(Test.java:17)... 2 more
标签:== got com 技术 程序猿 基本 into 打印 注意
原文地址:http://www.cnblogs.com/deng-cc/p/7462539.html