原txt文件内容如下:
“FXH-05”,“我是中国人”,“ggfhsdg发” ,“654321”,“谢谢你!”,007
#
325,1643,133,1157
131,6423,241,22122
#
325,1423,133,1857
131,1223,211,22265
编写代码处理后,变成:
“FXH-05” “我是中国人” “ggfhsdg发” “654321” “谢谢你!” 007
325 1643 133 1157
131 6423 241 22122
325 1423 133 1857
131 1223 211 22265
代码如下:
public class main {
public static void main(String[] args) throws IOException {
FileReader fr=null;
BufferedReader br =null;
String s=null;
String[] arrayTemp=null;
List<String[]> contentArrays=new ArrayList<String[]>();
try {
fr=new FileReader(new File("d:\\test.txt"));
br=new BufferedReader(fr);
while((s=br.readLine())!=null){
if(s.equals("#")) continue;
arrayTemp=s.split(",");
contentArrays.add(arrayTemp);
}
for(int i=0;i<contentArrays.size();i++){
arrayTemp=contentArrays.get(i);
for(String l:arrayTemp)
System.out.print(l+" ");
System.out.println();
}
} catch (FileNotFoundException e) {
// TODO Auto-generated catch block
e.printStackTrace();
}
finally{
br.close();
fr.close();
}
}
}