散分,请大家指教皆提些建议!参与者有分!绝不吝啬!
对于我来说已经是老身常谈了,依旧是处理文本文件的!我下面贴出一段代码,也是CSDN上的诸多热心朋友帮我完成的!因为我是初学者!
这段代码实现了读取一个文本文件,经处理过后再存入另一个文件!这样的功能已经实现了,现在我出现新的问 题,请大家先看段代码:package ReadFileA;
import java.util.*;
import java.io.*;
public class ReadFileA1 {
public ReadFileA1() {
}
public static void main(String args[]){
ReadFileA1 test = new ReadFileA1();
String strfile = ".\\data\\from.txt";
Vector vctValue = new Vector() ;
vctValue = test.ReadFile(strfile) ;
System.out.println("In File" + strfile + " : " ) ;
try{
PrintWriter out = new PrintWriter(new FileWriter(".\\data\\to.txt"));
String line;
for (int i=0; i<vctValue.size() ; i++){
System.out.println( vctValue.get(i) ) ;
line = (String)vctValue.get(i);
out.println(line);
}
out.flush();
out.close();
}
catch(IOException e)
{
e.printStackTrace();
}
}
private Vector ReadFile(String strInFile) {
Vector vctInFile = new Vector() ;
String strLine = "" ;
int intLoop ;
try {
//这是建立了一个文件读取对象
BufferedReader bfrdInFile = new BufferedReader(new FileReader(strInFile));
strLine = bfrdInFile.readLine();
intLoop = 0 ;
while (strLine != null) {
strLine = strLine.trim() ;
if(strLine.startsWith("<")||strLine.equals("")) {
strLine = bfrdInFile.readLine();
continue;
}
else {
vctInFile.add( intLoop,intLoop +" : " + strLine ) ;
intLoop++ ;
}
strLine = bfrdInFile.readLine();
}
bfrdInFile.close();
}
catch (Exception e) {
e.printStackTrace() ;
}
return vctInFile;
}
}
现在就相当于我有一打的from.txt一样的文本文伯,每个内容都不一样,但是处理方法是一样的,我现在要把这一打的文都处理,然后再存入一个新的文件,现在问题出来了,我不可以把每一个文本文件都带入代码里面来处理吧,如果我有一千个这样的文件,工作量不是很大吗,所以听一个朋友提议用dir > FILENAME.TXT就可以实现,但是具体的操作我不是很明白,但是新存入的文件名应该怎么取呢!处理了N个这样的文本文件,就有N个要存的新文件,还请大家指教,应该用什么样的办法会简单一些呢,多提点建议,谢谢!