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 阅读(139) 评论(0)  编辑  收藏


只有注册用户登录后才能发表评论。


网站导航:
 

公告

希望有一天

我能用鼠标双击我的钱包

然后选中一张100元

按住“ctrl+c”

接着不停的“ctrl+v”

嘻嘻~~~笑醒~~~



导航

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

统计

常用链接

留言簿(6)

随笔分类(102)

随笔档案(398)

文章分类

文章档案(10)

有趣网络

搜索

积分与排名

最新评论

阅读排行榜

评论排行榜