package com.why;
import java.io.File;
import java.io.FileInputStream;
import java.io.FileNotFoundException;
import java.io.IOException;
import java.io.InputStreamReader;
import java.util.ArrayList;
import java.util.List;
public class Test {
/**
* @param args
*/
public static void main(String[] args) {
File file = new File("D:\\A.txt");
FileInputStream input;
try {
input = new FileInputStream(file);
InputStreamReader reader = new InputStreamReader(input);
int b;
String s = "";
List<String> list = new ArrayList<String>();
while((b=reader.read())!=-1){
if(b==10 || b==13){
list.add(s);
s="";
}
else{
char c = (char) b;
s+=String.valueOf(c);
}
}
for(int j=0;j<list.size();j++){
System.out.println((String)list.get(j));
}
} catch (FileNotFoundException e) {
// TODO Auto-generated catch block
e.printStackTrace();
} catch (IOException e) {
// TODO Auto-generated catch block
e.printStackTrace();
}
}
}
package com.why;
import java.io.BufferedReader;
import java.io.File;
import java.io.FileInputStream;
import java.io.FileNotFoundException;
import java.io.IOException;
import java.io.InputStreamReader;
import java.util.ArrayList;
import java.util.List;
public class Test {
/**
* @param args
*/
public static void main(String[] args) {
File file = new File("D:\\A.txt");
FileInputStream input;
try {
input = new FileInputStream(file);
InputStreamReader reader = new InputStreamReader(input);
BufferedReader breader=new BufferedReader(reader);
String s = breader.readLine();
while(s!=null){
System.out.println(s);
s = breader.readLine();
}
} catch (FileNotFoundException e) {
// TODO Auto-generated catch block
e.printStackTrace();
} catch (IOException e) {
// TODO Auto-generated catch block
e.printStackTrace();
}
}
}