当前位置: 技术问答>java相关
一个JAVABEAN的例子程序出问题。(在线)
来源: 互联网 发布时间:2015-06-03
本文导语: 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 =...
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中却连编译也通不过
----------------
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中却连编译也通不过
|
先保存一下,再编译看看,注意路径。
|
没什么区别! 你的程序里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(...)
{...}
同时, 因为你在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(...)
{...}