我做了一个javaBean计数器,jsp调用如下:
<jsp:useBean id="counter" scope="request" class="com.jsq.Counter">
</jsp:useBean>
<%
//调用counter对象的readfile方法来读取文件lyfcount.txt中的计数
String cont=counter.ReadFile("count.txt");
//调用counter对象的readfile方法来将计数器加一后写入到文件lyfcount.txt中
counter.WriteFile("count.txt",cont);
%>
不管我用相对路径还是绝对路径都不对,先后用了/count.txt,./count.txt等,并且在每一级目录下都放了count.txt文件,都报错:
type Status report
message lyfcount.txt (系统找不到指定的文件。)
description The requested resource (lyfcount.txt (系统找不到指定的文件。)) is not available.---------javaBean文件------package com.jsq;
import java.io.*;
public class Counter extends Object {
private String currentRecord = null;
private BufferedReader file;
private String path;
public Counter() {
}
public String ReadFile(String filePath) throws FileNotFoundException{
path = filePath;
file = new BufferedReader(new FileReader(path));
String returnStr =null;
try {
currentRecord = file.readLine();}
catch (IOException e)
{
System.out.println("读取错务"); }
if (currentRecord == null)
returnStr = "没有任何记录";
else{
returnStr =currentRecord; }
return returnStr;
}
public void WriteFile(String filePath,String counter) throws FileNotFoundException
{
path = filePath;
int Writestr = Integer.parseInt(counter)+1;
try {
PrintWriter pw = new PrintWriter(new FileOutputStream(filePath));
pw.println(Writestr);
pw.close();
}catch(IOException e) {
System.out.println("错误"+e.getMessage()); }
}
}
<jsp:useBean id="counter" scope="request" class="com.jsq.Counter">
</jsp:useBean>
<%
//调用counter对象的readfile方法来读取文件lyfcount.txt中的计数
String cont=counter.ReadFile("count.txt");
//调用counter对象的readfile方法来将计数器加一后写入到文件lyfcount.txt中
counter.WriteFile("count.txt",cont);
%>
不管我用相对路径还是绝对路径都不对,先后用了/count.txt,./count.txt等,并且在每一级目录下都放了count.txt文件,都报错:
type Status report
message lyfcount.txt (系统找不到指定的文件。)
description The requested resource (lyfcount.txt (系统找不到指定的文件。)) is not available.---------javaBean文件------package com.jsq;
import java.io.*;
public class Counter extends Object {
private String currentRecord = null;
private BufferedReader file;
private String path;
public Counter() {
}
public String ReadFile(String filePath) throws FileNotFoundException{
path = filePath;
file = new BufferedReader(new FileReader(path));
String returnStr =null;
try {
currentRecord = file.readLine();}
catch (IOException e)
{
System.out.println("读取错务"); }
if (currentRecord == null)
returnStr = "没有任何记录";
else{
returnStr =currentRecord; }
return returnStr;
}
public void WriteFile(String filePath,String counter) throws FileNotFoundException
{
path = filePath;
int Writestr = Integer.parseInt(counter)+1;
try {
PrintWriter pw = new PrintWriter(new FileOutputStream(filePath));
pw.println(Writestr);
pw.close();
}catch(IOException e) {
System.out.println("错误"+e.getMessage()); }
}
}
解决方案 »
- java国际化中文乱码问题,我下载ResourceBundleEditor_v0.8.0粘贴之后,还有问题?
- 关于Open Flash Chart(OFC)不支持中文问题
- 求一个SSH实际项目.越大越好.
- 验证码中的一个小问题!
- JSP傻问题
- 求救,在基于WEB的图书管理系统中,当管理员登陆时要实现自动提示的谁借的书已经过期?
- ibatis 关于打印sql语句的问题
- http://java.sun.com/jsp/jstl/core_rt cannot be resolved in either web.xml or the jar files
- JSP使用JavaBean问题
- apache啟動時發生錯誤:
- WAP开发的语言选择问题 JSP or .NET ?
- jsp页面中调用某个类的方法,得不到返回值?
type Status report
message count.txt (系统找不到指定的文件。)
description The requested resource (count.txt (系统找不到指定的文件。)) is not available.
server.xml中的appBase="E:\0MyProjects\bbs\"
E:\0MyProjects\bbs\目录下:
\jsq\文件夹,下面有
\WEB-INF\文件夹
test.jsp文件WEB-INF\classes\com\jsq\Counter.class
我在\bbs\,\jsq\,\WEB-INF\,\classes\,\jsq\都放了count.txt,还是报“系统找不到指定的文件”
我先前用的是“E:\0MyProjects\bbs\jsq\count.txt”
改成"E:\\0MyProjects\\bbs\\jsq\\count.txt"就好了,为什么要“\\”两个斜杠,相对路径怎么写?
我放到包里面 与class 一起,同样报错
E:\0MyProjects\bbs\jsq\
-->jsq\
|---WEB-INF\
|---test.jsp
|---count.txt
|
浏览器访问是http://191.168.12.68/jsq/test.jsp
这样的,我test.jsp中路径这样写?
---------------------------------------------------------------------
<jsp:useBean id="counter" scope="request" class="com.jsq.Counter">
</jsp:useBean>
<%
//调用counter对象的readfile方法来读取文件lyfcount.txt中的计数
String cont=counter.ReadFile("file/count.txt");
//调用counter对象的readfile方法来将计数器加一后写入到文件lyfcount.txt中
counter.WriteFile("file/count.txt",cont);
%>
counter.WriteFile("E:/0MyProjects/bbs/jsq/count.txt",cont);
这样写没有错误!
out.println(System.getProperty("user.dir")+"<br>");解决