文本:
中国有140000000人口,平均年龄78.3岁
有4个直辖市,
这里有14首歌,是5个人做的
日本有25000000人口,平均年龄80岁
有9个直辖市,
据悉,去年,福州国企共承接178项总投资1911亿元的投资项目。其中,交建集团、
城乡建总、水务投资、新榕城建和房地产发展集团等5家公司就承接了172项投资项
目,属于五大战役项目的63项,总投资1178亿元,分别占项目数和总投资的35.4%和
62%。
现在已经可以运行打印出来,但还不清楚如何存入到oracle数据库中(存入格式为 第X行,第X个)。最近刚开始学基础的,很多都不会,汗
望高手能够帮忙解答下,谢谢~
付代码:
import java.io.BufferedReader;
import java.io.FileInputStream;
import java.io.IOException;
import java.io.InputStreamReader;
import java.io.LineNumberReader;
import java.util.regex.Matcher;
import java.util.regex.Pattern;
public class ReadSelectedLine {
static {
System.out.println("第X行\t第X个\t数字");
}
static void readLineVarFile(String lineStr, int lineNumber) throws IOException {
StringBuffer strBuffer = new StringBuffer();
int l = lineStr.length();
int indexpost = 0;
for(int i=0;i<l;i++){
int ca = lineStr.charAt(i);
if((ca>47 && ca<58) || ca==46){
strBuffer.append(String.valueOf(lineStr.charAt(i)));
}else{
if(strBuffer!=null){
String temp = strBuffer.toString();
if(temp!=null && !"".equals(temp)){
System.out.println(lineNumber+"\t"+(++indexpost)+"\t"+temp);
}
}
strBuffer = new StringBuffer();
}
}
}
// 文件内容的总行数。
static int getTotalLines(String fileName) throws IOException {
BufferedReader in = new BufferedReader(new InputStreamReader(
new FileInputStream(fileName)));
LineNumberReader reader = new LineNumberReader(in);
String s = reader.readLine();
int lines = 0;
while (s != null) {
lines++;
s = reader.readLine();
}
reader.close();
in.close();
return lines;
}
public static void main(String[] args) throws IOException {
// 读取文件
String fileName = "d:/111.txt";
// 获取文件的内容的总行数
int totalNo = getTotalLines(fileName);
//System.out.println("There are "+totalNo+ " lines in the text!");
BufferedReader reader = new BufferedReader(new InputStreamReader(
new FileInputStream(fileName)));
String lineStr;
for(int i=0;i<totalNo; i++){
lineStr = reader.readLine();
readLineVarFile(lineStr,i+1);
}
}
}
解决方案 »
免费领取超大流量手机卡,每月29元包185G流量+100分钟通话, 中国电信官方发货