public static void main(String[] args) {
File f = new File("D:\\eclipse\\workspace\\ltp_new\\input");
boolean b = false;
try {
fen_ju.fileList(f);
} catch (Exception e) {
}
}
public static void fileList(File file) {
File[] files = file.listFiles();
if (files != null) {
for (File f1 : files) {
System.out.println(f1.getAbsolutePath());
try{
FileInputStream file_reader = new FileInputStream(f1.getAbsolutePath());
InputStreamReader reader = new InputStreamReader(file_reader, "utf-8");
BufferedReader br = new BufferedReader(reader);
for (String line1 = br.readLine(); line1!=null; line1 = br.readLine()){
System.out.println(line1);
if(line1.compareTo("")!=0 && line1.compareTo("\t")!=0&&line1.compareTo(" ")!=0)
{ //System.out.println("不是 空白!!");
String text[]= line1.split("。|;|;");
for(int i=0;i<text.length;i++){
text[i]= text[i].replaceAll("\\s*", "");
if(text[i].compareTo("。")!=0){
char a[]=text[i].toCharArray();
int if_shang=0;
for(int j=0;j<a.length;j++){
if(a[j]=='"'&&if_shang==0)
{ a[j]='“';
if_shang=1;}
else if(a[j]=='"'&&if_shang==1)
a[j]='”';
}
text[i]="";
for(int j=0;j<a.length;j++){
text[i]=text[i]+a[j];
}
Write(text[i]+"。","fen_ju_out");
}
}
}
}
}
catch(Exception e)
{
System.out.println("1"+e);
fileList(f1);
}
}
}
}
JAVA遍历某个目录下的文件并读取
最新推荐文章于 2024-08-02 19:17:46 发布