有一规则文本需读出
如
aaaa,1212121
bbb,458048509
怎么读出来啊 读出来还要放到数据库对应的字段中去?
我看到的程序是这样的:
<%@ page contentType="text/html;charset=gb2312"%>
<%@ page import="java.io.*,java.lang.*"%>
<html>
<head>
<title>读取所有的文件数据</title>
</head>
<body>
<%
String path=request.getRealPath(".");
FileReader fr=new FileReader(path + "\\ReadData.txt");
//关键在于读取过程中,要判断所读取的字符是否已经到了文件的末尾,并且这个字符是不是文件中的断行符,即判断该字符值是否为13。
int c=fr.read();//从文件中读取一个字符
//判断是否已读到文件结尾
while(c!=-1){
out.print((char)c);//输出读到的数据
c=fr.read();//从文件中继续读取数据
if(c==13){//判断是否为断行字符
out.print("<br>");//输出分行标签
fr.skip(1);//略过一个字符
//c=fr.read();//读取一个字符
}
}
fr.close();
%>
</body>
</html>
但读出来的是char(c)
怎么放到String去
请教各位大侠了
如
aaaa,1212121
bbb,458048509
怎么读出来啊 读出来还要放到数据库对应的字段中去?
我看到的程序是这样的:
<%@ page contentType="text/html;charset=gb2312"%>
<%@ page import="java.io.*,java.lang.*"%>
<html>
<head>
<title>读取所有的文件数据</title>
</head>
<body>
<%
String path=request.getRealPath(".");
FileReader fr=new FileReader(path + "\\ReadData.txt");
//关键在于读取过程中,要判断所读取的字符是否已经到了文件的末尾,并且这个字符是不是文件中的断行符,即判断该字符值是否为13。
int c=fr.read();//从文件中读取一个字符
//判断是否已读到文件结尾
while(c!=-1){
out.print((char)c);//输出读到的数据
c=fr.read();//从文件中继续读取数据
if(c==13){//判断是否为断行字符
out.print("<br>");//输出分行标签
fr.skip(1);//略过一个字符
//c=fr.read();//读取一个字符
}
}
fr.close();
%>
</body>
</html>
但读出来的是char(c)
怎么放到String去
请教各位大侠了
import java.io.FileInputStream;
import java.io.FileNotFoundException;
import java.io.IOException;
import java.io.InputStreamReader;
public class ReadFile{
public static void main(String args[]){
String s;
try{
BufferedReader in=new BufferedReader(new InputStreamReader(new FileInputStream("d://Test.txt")));
while((s=in.readLine())!=null)
System.out.println("Read:"+s);
}catch(FileNotFoundException e){
System.out.println("File ont found!");
System.exit(-2);
}catch(IOException e){
System.out.println("Error:"+e);
System.exit(-3);
}
}
}