友情提示:如果本网页打开太慢或显示不完整,请尝试鼠标右键“刷新”本网页!阅读过程发现任何错误请告诉我们,谢谢!! 报告错误
狗狗书籍 返回本书目录 我的书架 我的书签 TXT全本下载 进入书吧 加入书签

Java编程思想第4版[中文版](PDF格式)-第266章

按键盘上方向键 ← 或 → 可快速上下翻页,按键盘上的 Enter 键可回到本书目录页,按键盘上方向键 ↑ 可回到本页顶部!
————未阅读完?加入书签已便下次继续阅读!



      Pr。error(〃could not open 〃 + f);  

    }  

    return in;  

  }  

  static BufferedReader disOpen(String fname) {  

    return disOpen(new File(fname));  

  }  

  static DataOutputStream dosOpen(File f) {  

    DataOutputStream in = null;  

    try {  

      in = new DataOutputStream(  

        new BufferedOutputStream(  

          new FileOutputStream(f)));  

    } catch(IOException e) {  

      Pr。error(〃could not open 〃 + f);  

    }  

    return in;  

  }  

  static DataOutputStream dosOpen(String fname) {  

    return dosOpen(new File(fname));  

  }  

  static PrintWriter psOpen(File f) {  

    PrintWriter in = null;  

    try {  

      in = new PrintWriter(  

        new BufferedWriter(  

          new FileWriter(f)));  

    } catch(IOException e) {  

      Pr。error(〃could not open 〃 + f);  



                                                                                             623 


…………………………………………………………Page 625……………………………………………………………

    }  

    return in;  

  }  

  static PrintWriter psOpen(String fname) {  

    return psOpen(new File(fname));  

  }  

  static void close(Writer os) {  

    try {  

      os。close();  

    } catch(IOException e) {  

      Pr。error(〃closing 〃 + os);  

    }  

  }  

  static void close(DataOutputStream os) {  

    try {  

      os。close();  

    } catch(IOException e) {  

      Pr。error(〃closing 〃 + os);  

    }  

  }  

  static void close(Reader os) {  

    try {  

      os。close();  

    } catch(IOException e) {  

      Pr。error(〃closing 〃 + os);  

    }  

  }  

}  

  

class SourceCodeFile {  

  public static final String   

    startMarker = 〃//:〃; // Start of source file  

    endMarker = 〃} ///:~〃; // End of source  

    endMarker2 = 〃}; ///:~〃; // C++ file end  

    beginContinue = 〃} ///:Continued〃;  

    endContinue = 〃///:Continuing〃;  

    packMarker = 〃###〃; // Packed file header tag  

    eol = // Line separator on current system  

      System。getProperty(〃line。separator〃);  

    filesep = // System's file path separator  

      System。getProperty(〃file。separator〃);  

  public static String copyright = 〃〃;  

  static {  

    try {  

      BufferedReader cr =  

        new BufferedReader(  

          new FileReader(〃Copyright。txt〃));  

      String crin;  

      while((crin = cr。readLine()) != null)  

        copyright += crin + 〃n〃;  

      cr。close();  

    } catch(Exception e) {  



                                                                                             624 


…………………………………………………………Page 626……………………………………………………………

      copyright = 〃〃;  

    }  

  }  

  private String filename; dirname;  

    contents = new String();  

  private static String chapter = 〃c02〃;  

  // The file name separator from the old system:  

  public static String oldsep;  

  public String toString() {  

    return dirname + filesep + filename;  

  }  

  // Constructor for parsing from document file:  

  public SourceCodeFile(String firstLine;   

      BufferedReader in) {  

    dirname = chapter;  

    // Skip past marker:  

    filename = firstLine。substring(  

        startMarker。length())。trim();  

    // Find space that terminates file name:  

    if(filename。indexOf(' ') != …1)  

      filename = filename。substring(  

          0; filename。indexOf(' '));  

    System。out。println(〃found: 〃 + filename);  

    contents = firstLine + eol;  

    if(copyright。length() != 0)  

      contents += copyright + eol;  

    String s;  

    boolean foundEndMarker = false;  

    try {  

      while((s = in。readLine()) != null) {  

        if(s。startsWith(startMarker))  

          Pr。error(〃No end of file marker for 〃 +  

            filename);  

        // For this program; no spaces before   

        // the 〃package〃 keyword are allowed  

        // in the input source code:  

        else if(s。startsWith(〃package〃)) {  

          // Extract package name:  

          String pdir = s。substring(  

            s。indexOf(' '))。trim();  

          pdir = pdir。substring(  

            0; pdir。indexOf(';'))。trim();  

          // Capture the chapter from the package  

          // ignoring the '' subdirectories:  

          if(!pdir。startsWith(〃〃)) {  

            int firstDot = pdir。indexOf('。');  

            if(firstDot != …1)  

              chapter =   

                pdir。substring(0;firstDot);  

            else  

              chapter = pdir;  

          }  



                                                                                        625 


…………………………………………………………Page 627……………………………………………………………

          // Convert package name to path name:  

          pdir = pdir。replace(  

            '。'; filesep。charAt(0));  

          System。out。println(〃package 〃 + pdir);  

          dirname = pdir;  

        }  

        contents += s + eol;  

        // Move past continuations:  

        if(s。startsWith(beginContinue))  

          while((s = in。readLine()) != null)  

            if(s。startsWith(endContinue)) {  

              contents += s + eol;  

              break;  

            }  

        // Watch for end of code listing:  

        if(s。startsWith(endMarker) ||  

           s。startsWith(endMarker2)) {  

          foundEndMarker = true;  

          break;  

        }  

      }  

      if(!foundEndMarker)  

        Pr。error(  

          〃End marker not found before EOF〃);  

      System。out。println(〃Chapter: 〃 + chapter);  

    } catch(IOException e) {  

      Pr。error(〃Error reading line〃);  

    }  

  }  

  // For recovering from a packed file:  

  public SourceCodeFile(BufferedReader pFile) {  

    try {  

      String s = pFile。readLine();  

      if(s == null) return;  

      if(!s。startsWith(packMarker))  

        Pr。error(〃Can't find 〃 + packM
返回目录 上一页 下一页 回到顶部 0 0
未阅读完?加入书签已便下次继续阅读!
温馨提示: 温看小说的同时发表评论,说出自己的看法和其它小伙伴们分享也不错哦!发表书评还可以获得积分和经验奖励,认真写原创书评 被采纳为精评可以获得大量金币、积分和经验奖励哦!