系统找不到指定的文件是怎么回事,我明明在D盘有EE.txt这个文件啊?不过里面是空的,是这个原因?
为什么下面的程序会出现这种错误?HTTP Status 404 - D:null (系统找不到指定的文件。)
--------------------------------------------
type Status report
message D:null (系统找不到指定的文件。)
description The requested resource (D:null (系统找不到指定的文件。)) is not available.
--------------------------------------------
Apache Tomcat/5.5.9
这是我的两个JSP页面toupiao1.jsp和toupiao2.jsp
toupiao1.jsp页面
<%@page contentType= "text/html;charset=GBK " %>
<%@page import= "java.util.* " %>
<%@page import= "java.lang.* " %>
<%@page import= "java.io.* " %>
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN " "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd ">
<html xmlns= "http://www.w3.org/1999/xhtml ">
<head>
<meta http-equiv= "Content-Type " content= "text/html; charset=gb2312 " />
<title> 在线投票 </title>
</head>
<body bgcolor= "#ffffff ">
<center>
<table width= "300 " border= "1 " cellspacing= "0 " cellpadding= "0 ">
<tr>
<td> 投票题目:你认为JSP容易学么? </td>
</tr>
<form name= "toupiao " method= "post " action= "toupiao2.jsp ">
<tr>
<td>
<input type= "radio " name= "toup " value= "one " checked= "checked "/> 较难 <br>
<input type= "radio " name= "toup " value= "two "> 一般 <br>
<input type= "radio " name= "toup " value= "three "> 容易 <br>
<input type= "submit " name= "submit " value= "提交 ">
</td> </tr>
<tr>
<td>
<%
//投票的结果放在酵目录的一个文本文件中,先打到这个文件,并且判断其是否存在,如果不存在,则创建一个文本文件
//一般情况下,应该在里面加上判断异常的语句。由于已经创建了EE.txt文件,所以在这里就不用了。
String resultsDir= "D: ";
FileInputStream tfile=new FileInputStream(resultsDir+System.getProperty( "file.separator "+ "EE.txt "));
//在EE.txt中,投票结果是存为 "Number1:Number2:Number3 "的,因此,在处理程序中,首先要读取原来的结果,
//分别为Number1、Number2、Number3,最后再关闭文件EE.txt
String str= " ";
int c;
while((c=tfile.read())!=-1){
str=str+(char)c;
}
int first=str.indexOf( ": ");
int last=str.lastIndexOf( ": ");
int lenth=str.length();
String First=str.substring(0,first);
String Next=str.substring(first+1,last);
String Last=str.substring(last+1,lenth);
tfile.close();
//新旧结果相加和显示
Long a1=new Long(first);
Long a2=new Long(Next);
Long a3=new Long(Last);
long b1=a1.longValue();
long b2=a2.longValue();
long b3=a3.longValue();
long total=b1+b2+b3;
float h0=100*((float)b1/(float)total);
float h1=100*((float)b2/(float)total);
float h2=100*((float)b3/(float)total);
out.println( "Select1 <img src=reg.gif width= "+h0+ "height=15 "+b1+ "> <br> ");
out.println( "Select2 <img src=reg.gif width= "+h1+ "height=15 "+b2+ "> <br> ");
out.println( "Select3 <img src=reg.gif width= "+h2+ "height=15 "+b3+ "> <br> ");
out.println( "Total: "+total);
%>
</td>
</tr>
</form>
</table>
</center>
</body>
</html>
toupiao2.jsp页面
<%@ page contentType= "text/html; charset=GBK " %>
<%@page import= "java.util.* " %>
<%@page import= "java.lang.* " %>
<%@page import= "java.io.* " %>
<%
String action=request.getParameter( "action ");
String toup=request.getParameter( "toupiao ");
String mydata= " ";
if(action.compareTo( "toupiao ")==0){
String resultsDir= "D: ";
FileWriter resultsFile=new FileWriter(resultsDir+System.getProperty( "file.separator ")+ "EE.txt ",true);
File myfile=new File(resultsDir+System.getProperty( "file.separator ")+ "EE.txt ");//?
if(!(myfile.exists())){
PrintWriter toFile=new PrintWriter(resultsFile);
if(toup.compareTo( "one ")==0) mydata= "1:0:0 ";//哪来的mydata
if(toup.compareTo( "two ")==0) mydata= "0:1:0 ";
if(toup.compareTo( "three ")==0) mydata= "0:0:1 ";
toFile.println(mydata);
resultsFile.close();
out.println(mydata);
}else{
FileInputStream tfile=new FileInputStream(resultsDir+System.getProperty( "file.separator ")+ "EE.txt ");
String str= " ";
int c;
while((c=tfile.read())!=-1){
str=str+(char)c;
}
int first=str.indexOf( ": ");
int last=str.indexOf( ": ");
int lenth=str.length();
String First =str.substring(0,first);
String Next=str.substring(first+1,last);
String Last=str.substring(last+1,lenth);
tfile.close();
Long a1=new Long(First);
Long a2=new Long(Next);
Long a3=new Long(Last);
long b1=a1.longValue();
long b2=a2.longValue();
long b3=a3.longValue();
if(toup.compareTo( "one ")==0) b1=b1+1;
if(toup.compareTo( "two ")==0) b2=b2+1;
if(toup.compareTo( "three ")==0) b3=b3+1;
Long c1=new Long(b1);
Long c2=new Long(b2);
Long c3=new Long(b3);
String d1=c1.toString();
String d2=c2.toString();
String d3=c3.toString();
str=d1+ ": "+d2+ ": "+d3;
RandomAccessFile savefile=new RandomAccessFile(resultsDir+System.getProperty( "file.separator ")+ "EE.txt ", "rw ");
savefile.writeBytes(str);
savefile.close();
}
%>
<SCRIPT language= "JavaScript " type= " ">
alert( "Thank you! ");
self.location= "toupiao1.jsp ";
</SCRIPT>
<%
}
%>
[解决办法]
JSP和SERVLET在客户端不能访问本地文件,只能访问服务器的
http://topic.csdn.net/t/20011219/11/429996.html
[解决办法]
D:null (系统找不到指定的文件。)
FileInputStream tfile=new FileInputStream(resultsDir+System.getProperty( "file.separator "+ "EE.txt "));
D:\
试试
FileInputStream tfile=new FileInputStream(resultsDir+System.getProperty( "file.separator ")+ "EE.txt ");
或者干脆
FileInputStream tfile=new FileInputStream(resultsDir+ "\EE.txt "); // 是反斜杠或正斜杠自己试验下
[解决办法]
FileInputStream(resultsDir+System.getProperty( "file.separator "+ "EE.txt "));应该是:
FileInputStream(resultsDir+System.getProperty( "file.separator ")+ "EE.txt ");
[解决办法]
如楼上,楼主粗心了.
[解决办法]
FileInputStream(resultsDir+System.getProperty( "file.separator ")+ "EE.txt ");
括号位置错了