Using BufferedReader to read Text File

前端 未结 9 1518
你的背包
你的背包 2020-11-29 04:29

I\'m having problems with using the BufferedReader

I want to print the 6 lines of a text file:

public class Reader {

public static void main(String[         


        
9条回答
  •  误落风尘
    2020-11-29 05:21

    private void readFile() throws Exception {
          AsynchronousFileChannel input=AsynchronousFileChannel.open(Paths.get("E:/dicom_server_storage/abc.txt"),StandardOpenOption.READ);
          ByteBuffer buffer=ByteBuffer.allocate(1024);
          input.read(buffer,0,null,new CompletionHandler(){
            @Override public void completed(    Integer result,    Void attachment){
              System.out.println("Done reading the file.");
            }
            @Override public void failed(    Throwable exc,    Void attachment){
              System.err.println("An error occured:" + exc.getMessage());
            }
          }
        );
          System.out.println("This thread keeps on running");
          Thread.sleep(100);
        }
    

提交回复
热议问题