Jsp求解 在线等答案!!谢谢!!!

来源:百度知道 编辑:UC知道 时间:2024/06/22 06:35:52
package jb;
import java.io.*;
import java.io.IOException;
public class Bean1 {
private String path =null;
private String strread ="0";
private String strwrite = "0";
public Bean1() {
}

public String getPath() {
return path;
}

public void setPath(String path) {
this.path = path;
}

public String getStrread() {
return strread;
}

public void setStrread(String strread) {
this.strread = strread;
}

public String getStrwrite() {
return strwrite;
}

public void setStrwrite(String strwrite) {
this.strwrite = strwrite;
}

public int reads(){
try {
File f1 = new File(path);
if (!f1.exists())
f1.createNewFile();
FileReader frd = new FileReader(f1);
BufferedReader bfd = new BufferedReader(frd);
String s = null;
while((s = bfd.readLine())!=null)
{
strread += s

while((s = bfd.readLine())!=null)
{
strread += s; //为什么是用 strread 连接 s??
}
//你的String s是用来读取文本内保存的数字的吧
那么读一次就可以了拉
if((s = bfd.readLine())!=null){
strread = s;
}

啥错误啊?

FileReader frd = new FileReader(f1);
BufferedReader bfd = new BufferedReader(frd);
String s = null;
while((s = bfd.readLine())!=null)
{
strread += s;
}

是不是这段问提啊?你可以将读出来的东西直接存入字符串吗?应该存入byte数组吧?

byte[] buffer = new byte[BUFFER_SIZE];
while (in.read(buffer) > 0 ) {
out.write(buffer);
}
然后再从buffer中读入out中