package com.xx;
import java.io.BufferedReader;
import java.io.File;
import java.io.FileNotFoundException;
import java.io.FileReader;
import java.io.IOException;
import java.util.ArrayList;
import java.util.List;
public class ReadNotes {
/**
*读取Pascal中的注释
*/
public static void main(String[] args) {
File file = new File("D:/报表.txt");
readFile(file);
}
/**
* 读取文件
* @param file 要读取的文件
*
*/
public static void readFile(File file){
List<String>list = new ArrayList<String>();
BufferedReader readfile = null;
try {
readfile = new BufferedReader(new FileReader(file));
String tempString = null;
int flag = 0;
while((tempString = readfile.readLine()) != null){
if(tempString.indexOf("//") != -1 ){
System.out.println(tempString);
}else if(tempString.indexOf("{") != -1 || flag == 1 && tempString.indexOf("}") == -1){
System.out.println(tempString);
flag = 1;
}else if(tempString.indexOf("}") != -1) {
System.out.println(tempString);
flag = 0;
}
}
} catch (FileNotFoundException e) {
e.printStackTrace();
} catch (IOException e) {
e.printStackTrace();
}finally{
if(readfile != null){
try {
readfile.close();
} catch (IOException e) {
e.printStackTrace();
}
}
}
}
}
读取Pascal中的注释
最新推荐文章于 2022-01-13 10:22:34 发布
本文提供了一个使用Java进行文件读取的示例程序,主要介绍了如何读取文本文件中的内容,并展示了处理文本中注释的基本逻辑。通过该示例,读者可以了解如何利用Java的BufferedReader类来逐行读取文件。
583

被折叠的 条评论
为什么被折叠?



