package dvb.epg.dtv;
import java.io.*;
import java.util.StringTokenizer;public class ReadFile
{
private String currentRecord = null;
private BufferedReader file;
private String path;
private StringTokenizer token;
//创建文件对象
public ReadFile()
{
    file=new BufferedReader(new InputStreamReader(System.in),1);
}
public ReadFile(String filePath) throws FileNotFoundException{
    path=filePath;
    file=new BufferedReader(new FileReader(path));
}
//设置文件路径
public void setPath(String filePath){
    path = filePath;
    try {
            file = new BufferedReader(new
            FileReader(path));
        }
    catch (FileNotFoundException e){
    }
}
//得到文件路径
public String getPath() {
    return path;
}
//关闭文件
public void fileClose() throws IOException
{
    file.close();
}
//读取下一行记录,若没有则返回-1
public int nextRecord() {
    int returnInt=-1;
    try{
        currentRecord = file.readLine();
    }catch (IOException e)
    {
    }
    if (currentRecord == null){
         returnInt=-1;
    }else{
         token=new StringTokenizer(currentRecord);
         returnInt=token.countTokens();
    }
    return returnInt;
}
public String returnRecord(){
    return currentRecord;
}
}

解决方案 »

  1.   

    再问一下有没有一种更好的办法, 比如在那个框中直接把文件拷过来呵呵我刚学JSP和JAVA所以............
      

  2.   

    要是我想读取Excel文件呢,好像不能用上面那种方法读,能不能用上面那个方法读
      

  3.   

    可以直接在ie打开此excel文件:
    tomcat/conf/web.xml下加:
    <mime-mapping> 
    <extension>xls</extension> 
    <mime-type>application/msexcel</mime-type> 
    </mime-mapping>
    需要导出的文件头上加:
    <%@ page contentType="application/vnd.ms-excel" %>