当前位置: 技术问答>java相关
问题很多,求助(在线)?
来源: 互联网 发布时间:2015-06-14
本文导语: counter.java 文件 package count; import java.io.*; public class counter extends Object { private String currentRecord =null; private String path =null; privat...
counter.java 文件
package count;
import java.io.*;
public class counter extends Object {
private String currentRecord =null;
private String path =null;
private BufferedReader file;
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(e+"读取数据错误");
}
if (currentRecord==null)
currentRecord="没有记录";
else
{
returnStr=currentRecord;
}
return returnStr;
}
public void WriteFile(String filePath,String counter) throws FileNotFoundException
{
path = filePath;
int Writerstr =Integer.parseInt(counter)+1;
try
{
//?????
//PrintWriter pw = new PrintWriter(new FileOutputStream(filePath));
PrintWriter pw = new PrintWriter(new FileOutputStream(path));
pw.println(Writerstr);
pw.close();
}
catch(IOException e)
{
System.out.println(e+"写入文件错误");
}
}
}
test.jsp文件
工作目录是路径
test/test.jsp
test/web-inf/class/count/counter.class
test/web-inf/class/count/count.txt
以上代码运行正确!
我现在有几个问题要问
1:为什么在代码中打了问号的位置
PrintWriter pw = new PrintWriter(new FileOutputStream(filePath));
代替:PrintWriter pw = new PrintWriter(new FileOutputStream(path));
编译通不过
2:count.txt 为什么要放在test/web-inf/class/count 下,按我的理解它应该和TEST。JSP在一个目录下
3:test.jsp中
request为什么不能改为application
4:如果我在counter.java 中我不 要这条语句package cout;编译后
test.jsp中改为
工作目录的相应路径改为
test/test.jsp
test/web-inf/class/counter.class
test/web-inf/class/count.txt
运行时
这句报错
说找不到
counter.class
package count;
import java.io.*;
public class counter extends Object {
private String currentRecord =null;
private String path =null;
private BufferedReader file;
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(e+"读取数据错误");
}
if (currentRecord==null)
currentRecord="没有记录";
else
{
returnStr=currentRecord;
}
return returnStr;
}
public void WriteFile(String filePath,String counter) throws FileNotFoundException
{
path = filePath;
int Writerstr =Integer.parseInt(counter)+1;
try
{
//?????
//PrintWriter pw = new PrintWriter(new FileOutputStream(filePath));
PrintWriter pw = new PrintWriter(new FileOutputStream(path));
pw.println(Writerstr);
pw.close();
}
catch(IOException e)
{
System.out.println(e+"写入文件错误");
}
}
}
test.jsp文件
工作目录是路径
test/test.jsp
test/web-inf/class/count/counter.class
test/web-inf/class/count/count.txt
以上代码运行正确!
我现在有几个问题要问
1:为什么在代码中打了问号的位置
PrintWriter pw = new PrintWriter(new FileOutputStream(filePath));
代替:PrintWriter pw = new PrintWriter(new FileOutputStream(path));
编译通不过
2:count.txt 为什么要放在test/web-inf/class/count 下,按我的理解它应该和TEST。JSP在一个目录下
3:test.jsp中
request为什么不能改为application
4:如果我在counter.java 中我不 要这条语句package cout;编译后
test.jsp中改为
工作目录的相应路径改为
test/test.jsp
test/web-inf/class/counter.class
test/web-inf/class/count.txt
运行时
这句报错
说找不到
counter.class
|
up下