高手请进。
/*******************************************************************************
* @类 名: Access()
* @类名功能: 对给定格式文件按自己要求进行读写。(*.txt)
* @类名版本: 1.0.0
* @设计作者: ZJY
* @开始时间: 2004-07-09
* @修改时间: 2004-08-02
*******************************************************************************/
package com.jxclic;
import java.io.*;
import java.util.*;
public class Access {
private String strFileName = null;
public Access() {
this.strFileName = "syssetup.ini";
}
public Access(String fullFileName) {
this.strFileName = fullFileName;
}
/***************************************************************************
函数功能:从给定的文本文件中读取相应信息形成数据库链接字符串.
***************************************************************************/
public String getConnectionUrl() throws Exception {
String strLine = null;
FileInputStream fisSetupFile = null;
BufferedReader brSetupFile = null;
StringTokenizer st = null;
//-------------------------
String strIp = null;
String strPort = null;
String strDbname= null;
String strServer= null;
String strUser = null;
String strPassword = null;
//----------------------------
String strToken = null;
String strConnectionUrl = null;
fisSetupFile = new FileInputStream(this.strFileName);
brSetupFile = new BufferedReader(new InputStreamReader(fisSetupFile));
while((strLine=brSetupFile.readLine()) !=null) {
st = new StringTokenizer(strLine,"=");
strToken = st.nextToken().trim();
while(st.hasMoreTokens()) {
if(strToken.equalsIgnoreCase("IP")) {
strIp = st.nextToken().trim();
}
if(strToken.equalsIgnoreCase("PORT")) {
strPort = st.nextToken().trim();
}
if(strToken.equalsIgnoreCase("DBNAME")) {
strDbname = st.nextToken().trim();
}
if(strToken.equalsIgnoreCase("DBSERVER")) {
strServer = st.nextToken().trim();
}
if(strToken.equalsIgnoreCase("USER")) {
strUser = st.nextToken().trim();
}
if(strToken.equalsIgnoreCase("PASSWORD")) {
strPassword = st.nextToken().trim();
}
}
}
strConnectionUrl = "jdbc:informix-sqli://"+ strIp +":"+ strPort +"/"+ strDbname;
strConnectionUrl+= ":informixserver="+ strServer +";user="+ strUser +";password="+ strPassword;
return(strConnectionUrl);
}
public static void main(String[] args) {
Access objTest = null;
String strTest = null;
objTest = new Access();
try {
strTest = objTest.getConnectionUrl();
System.out.println(strTest);
} catch (Exception ex) {
System.out.println(ex.getMessage());
}
}
}
在jcreator编译中通过。在我写的JSP中确报错。以下是我的JSP文件。
<%@ page import="com.jxclic.*,java.util.*" %>
<%@ page language="java" contentType="text/html;charset=gb2312" %>
<html>
<head>
<title>单位信息列表</title>
</head>
<%
Access obj = new Access();
try {
String a= obj.getConnectionUrl();
}catch(Exception ex) {
out.println("读取文件失败:"+ ex.getMessage());
}
%>
<body>
</body>
</html>
程序在执行obj.getConnectionUrl()时报错。[读取文件失败:syssetup.ini (系统找不到指定的文件。) ]
我把Access.class放到了D:\JAVA\Tomcat 5.0\webapps\ROOT\WEB-INF\classes\com\jxclic下。
syssetup.ini文件放到了D:\JAVA\Tomcat 5.0\webapps\ROOT\WEB-INF\classes\下。
请问这是为什么呀。