快捷搜索:  as  2018  FtCWSyGV  С˵  test  xxx  Ψһ  w3viyKQx

和记h188怡情_机器人论坛



文件操作是网站编程的紧张内容之一,asp关于文件操作评论争论的已经很多了,让我们和记h188怡情来看看jsp中是若何实现的。

这里用到了两个文件,一个jsp文件一个javabean文件,经由过程jsp中调用javabea和记h188怡情n可以轻松读取文本文件,留意请放置一个文本文件afile.txt到web根目录的test目录下,javabean文件编译后将class文件放到对应的class目录下(tomcat情况)。

Read.jsp

文件内容:

第行:

//DelimitedDataFile.java bean文件源代码

//导入java包

import java.io.*;

import java.util.StringTokenizer;

public class DelimitedDataFile

{

private String currentRecord = null;

private BufferedReader file;

private String path;

private StringTokenizer token;

//创建文件工具

public DelimitedDataFile()

{

file = new BufferedReader(new InputStreamReader(System.in),1);

}

public DelimitedDataFile(String filePath) throws FileNotFoundException

{

path = filePath;

file = new BufferedReader(new FileReader(path));

}

//设置文件路径

public void setPat和记h188怡情h(String filePath)

{

path = filePath;

try {

file = new BufferedReader(new

FileReade和记h188怡情r(path));

} catch (FileNotFoundException e) {

System.out.println("file not found");

}

}

//获得文件路径

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)

{

System.out.println("readLine problem, terminating.和记h188怡情");

}

if (currentRecord == null)

returnInt = -1;

else

{

token = new StringTokenizer(currentRecord);

returnInt = token.countTokens();

}

return returnInt;

}

//以字符串的形式返回全部记录

public String returnRecord()

{

return currentRecord;

}

}

您可能还会对下面的文章感兴趣: