一个JAVABEAN的例子程序出问题。(在线)

xddy 2002-05-17 08:08:15
counter.java
----------------

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+"写入文件错误");
}

}


}

在DOS下可以编译通过。但执行时JSP页面是出现问题。
我就哪到JBUILDER 6中却连编译也通不过
...全文
46 10 打赏 收藏 转发到动态 举报
写回复
用AI写文章
10 条回复
切换为时间正序
请发表友善的回复…
发表回复
alafeng 2002-05-21
  • 打赏
  • 举报
回复
没什么区别! 你的程序里path and filepath的值是一样的.

同时, 因为你在main()中调用readfile() and writefile() , but the main() method is staitc , so u must write the methods readfile() and writefile() to staitc. exp:
public static String readfile(...)
{...}

public static void writefile(...)
{...}
ppdy 2002-05-20
  • 打赏
  • 举报
回复
问一下,是用JBUILD6编写的吗?
rao713 2002-05-20
  • 打赏
  • 举报
回复
gz
xddy 2002-05-19
  • 打赏
  • 举报
回复
我还想问一个下,在写的代码中我打了问号的地方。两条语句有什么区别
xddy 2002-05-19
  • 打赏
  • 举报
回复
是这样的我在代码中加入
public static void main(String args[]) throws FileNotFoundException{

String cont="0";
cont=ReadFile("/count.txt");
WriteFile("count.txt",cont);

}
则编译报错

Dickensi 2002-05-19
  • 打赏
  • 举报
回复
你在哪里出错?
在哪里调用的ReadFile(java.lang.String)?
xddy 2002-05-19
  • 打赏
  • 举报
回复
"counter.java": Error #: 308 : non-static method ReadFile(java.lang.String) cannot be referenced from a static context at line 11, column 7
Dickensi 2002-05-18
  • 打赏
  • 举报
回复
你应该把它放在C:\Documents and Settings\Administrator\jbproject\untitled3\src\counter.java
下,
或者给代码加个包!
package untitled3;
Iforgot 2002-05-17
  • 打赏
  • 举报
回复
先保存一下,再编译看看,注意路径。
xddy 2002-05-17
  • 打赏
  • 举报
回复
"counter.java": Error #: 901 : package . stated in source C:\Documents and Settings\Administrator\jbproject\untitled3\src\untitled3\counter.java does not match directory untitled3

81,094

社区成员

发帖
与我相关
我的任务
社区描述
Java Web 开发
社区管理员
  • Web 开发社区
加入社区
  • 近7日
  • 近30日
  • 至今
社区公告
暂无公告

试试用AI创作助手写篇文章吧