今幫一朋友做了個讀取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的搜索歷史里摘出來的,呵呵,初感覺到搜索歷史還是有用的哦
。