package com.huawei.syper.an;
import java.io.BufferedReader;
import java.io.FileInputStream;
import java.io.FileNotFoundException;
import java.io.IOException;
import java.io.InputStreamReader;
import java.util.ArrayList;
/**
* 读行的写法
*/
public class AnasicTextv01
{
@SuppressWarnings({ "rawtypes", "unchecked" })
public static void main(String[] args)
{
try {
BufferedReader br = new BufferedReader(new InputStreamReader(new FileInputStream("D:/mytest/syper_cof.txt")));
ArrayList myFileList = new ArrayList<String>();
ArrayList myFileList2 = new ArrayList<String>();
String myFile = null;
try {
while((myFile=br.readLine())!=null)
{
if(myFile.equals("")){
continue;
}
//如果myFileList2中有数据的时候
if(myFileList2.size()>0)
{
for(int i=0;i<myFileList2.size();i++)
{
myFile = myFileList2.get(i) + myFile;
}
myFileList2.clear();
}
//如果一行的最后一个字符是" ;"的时候
if(myFile.lastIndexOf(";") == (myFile.length()-1))
{
myFileList.add(myFile);
}
//如果一行读完还没有" ;"的时候,把这条数据加入到另外一个list中
else
{
myFileList2.add(myFile);
}
}
for(int i=0;i<myFileList.size();i++)
{
//System.out.println(myFileList.get(i));
}
for(Object obj : myFileList)
{
String substr =(String)obj;
String[] sub = substr.split(":");
for(int j=0;j<sub.length;j++)
{
System.out.println(sub[j]);
}
System.out.println(obj);
}
br.close();
} catch (IOException e) {
// TODO Auto-generated catch block
e.printStackTrace();
}
} catch (FileNotFoundException e) {
// TODO Auto-generated catch block
e.printStackTrace();
}
}
}
import java.io.BufferedReader;
import java.io.FileInputStream;
import java.io.FileNotFoundException;
import java.io.IOException;
import java.io.InputStreamReader;
import java.util.ArrayList;
/**
* 读行的写法
*/
public class AnasicTextv01
{
@SuppressWarnings({ "rawtypes", "unchecked" })
public static void main(String[] args)
{
try {
BufferedReader br = new BufferedReader(new InputStreamReader(new FileInputStream("D:/mytest/syper_cof.txt")));
ArrayList myFileList = new ArrayList<String>();
ArrayList myFileList2 = new ArrayList<String>();
String myFile = null;
try {
while((myFile=br.readLine())!=null)
{
if(myFile.equals("")){
continue;
}
//如果myFileList2中有数据的时候
if(myFileList2.size()>0)
{
for(int i=0;i<myFileList2.size();i++)
{
myFile = myFileList2.get(i) + myFile;
}
myFileList2.clear();
}
//如果一行的最后一个字符是" ;"的时候
if(myFile.lastIndexOf(";") == (myFile.length()-1))
{
myFileList.add(myFile);
}
//如果一行读完还没有" ;"的时候,把这条数据加入到另外一个list中
else
{
myFileList2.add(myFile);
}
}
for(int i=0;i<myFileList.size();i++)
{
//System.out.println(myFileList.get(i));
}
for(Object obj : myFileList)
{
String substr =(String)obj;
String[] sub = substr.split(":");
for(int j=0;j<sub.length;j++)
{
System.out.println(sub[j]);
}
System.out.println(obj);
}
br.close();
} catch (IOException e) {
// TODO Auto-generated catch block
e.printStackTrace();
}
} catch (FileNotFoundException e) {
// TODO Auto-generated catch block
e.printStackTrace();
}
}
}