我有一个程序,它从文件中读取内容并将其打印在屏幕上。但是程序每隔一行打印一次,即跳过每隔一行。包输入输出;
import java.io.*;
public class CharacterFileReaderAndFileWriter{
private BufferedReader br = null;
private PrintWriter pw = new PrintWriter(System.out, true);
/* Read from file and print to console */
public void readFromFile() throws IOException{
try{
br = new BufferedReader(new FileReader("E:\\Programming\\Class files\\practice\\src\\InputOutput\\test.txt"));
}
catch(FileNotFoundException ex){
ex.printStackTrace();
}
String s = null;
do{
s = br.readLine();
pw.println(s);
}
while((s = br.readLine())!=null);
br.close();
}
/* Main method */
public static void main(String[] args) throws IOException{
CharacterFileReaderAndFileWriter cfr = new CharacterFileReaderAndFileWriter();
cfr.readFromFile();
}
}