Loading...

          java .net

          2007年6月4日 星期一

          今幫一朋友做了個讀取txt文件的代碼,掌握不扎實啊,寫這些還要多次查api幫助文檔,呵呵呵

          import java.io.FileInputStream;
          import java.io.FileNotFoundException;
          import java.io.IOException;
          import java.io.InputStreamReader;

          public class Test
          {
          public String readFile(String file)
          {
             String doc = null;
             StringBuffer fileText = new StringBuffer();
             FileInputStream infile;
             try {
              infile = new FileInputStream(file);

              InputStreamReader in = new InputStreamReader(infile);
              java.io.BufferedReader reader =new java.io.BufferedReader(in);
              while((doc=reader.readLine()) !=null)
              {
               if(!doc.equals("") && !doc.substring(0,1).equals("#"))
                fileText.append(doc+"\n");
              }

             } catch (FileNotFoundException e) {
              e.printStackTrace();
             }catch(IOException ie)
             {
              ie.printStackTrace();
             }
             return fileText.toString();
          }
          public static void main(String[] args)
          {
             String fileText = new Test().readFile("C://1.txt");
             System.out.println("fileText:\n");
             System.out.println(fileText);
          }
          }

          1.txt文件

          #Line1
          J2SE
          #cOMMENTS
          J2EE


          J2ME


          輸出


          J2SE
          J2EE


          J2ME

          從周五就開始搗鼓書生表單,今天有搗鼓了一天,想弄個練習出來,就是沒出來,呵呵呵

          總結一下遇到的異常

          java.lang.IllegalArgumentException: Document base C:\Tomcat 5.5\webapps\應用名 does not exist or is not a readable directory
          這樣的錯誤應在是在tomcat的Tomcat 5.5\conf\Catalina\localhost目錄下配置的針對該應用的連接池的xml文件,而在webapps中沒有這個應用

          org.apache.commons.configuration用來讀取配置文件的jar包commons-configuration-1.1.jar

          Castor是一種將Java對象和XML自動綁定的開源軟件. 它可以在Java對象,XML文本,SQL數據表以及LDAP目錄之間綁定.castor-0.9.5.jar

          org.hibernate.HibernateException: Hibernate Dialect must be explicitly set

          安裝字面意思是沒有設置方言

          <property name="hibernate.dialect">
                org.hibernate.dialect.Oracle9Dialect
          </property>

          org.hibernate.HibernateException: No CurrentSessionContext configured
          <!-- Enable Hibernate's automatic session context management -->
                <property name="current_session_context_class">thread</property>

          tomcat不加,要在程序里寫

          總結一點錯誤,從google的搜索歷史里摘出來的,呵呵,初感覺到搜索歷史還是有用的哦

          posted on 2008-08-26 22:06 閱讀(142) 評論(0)  編輯  收藏


          只有注冊用戶登錄后才能發表評論。


          網站導航:
           

          公告

          希望有一天

          我能用鼠標雙擊我的錢包

          然后選中一張100元

          按住“ctrl+c”

          接著不停的“ctrl+v”

          嘻嘻~~~笑醒~~~



          導航

          <2008年8月>
          272829303112
          3456789
          10111213141516
          17181920212223
          24252627282930
          31123456

          統計

          常用鏈接

          留言簿(6)

          隨筆分類(102)

          隨筆檔案(398)

          文章分類

          文章檔案(10)

          有趣網絡

          搜索

          積分與排名

          最新評論

          閱讀排行榜

          評論排行榜

          主站蜘蛛池模板: 响水县| 环江| 浦城县| 滨海县| 蒙阴县| 泾源县| 绥德县| 昌吉市| 昭苏县| 临沭县| 抚松县| 柯坪县| 东明县| 新源县| 罗定市| 怀来县| 获嘉县| 离岛区| 汕尾市| 永嘉县| 平罗县| 汤原县| 康马县| 明星| 柳河县| 新丰县| 神池县| 开原市| 揭东县| 福泉市| 丹寨县| 旬邑县| 永平县| 江安县| 获嘉县| 鄂尔多斯市| 威宁| 台中县| 连平县| 兴国县| 交城县|