2013-12-26 3 views
0

내 프로그램에서 파일에 출력을 쓰는 셸 스크립트를 실행하고 있습니다. 파일 내용을 한 줄씩 표시하려고합니다. 이 두 작업은 동시에 작동해야합니다. 나는 동시 읽기를 처리하고 작업을 쓰기 어떻게java를 사용하여 동시에 파일에서 읽고 쓰는 방법은 무엇입니까?

public static void myfun(String abc) throws IOException, InterruptedException { 
    String customer = "xyz"; 
    nmapoutfile=runMT.instdir+"/var/nmapout."+customer; 
    String nmapstatusfile = runMT.instdir+"/logs/nmapout."+customer+".log"; 
    String nmapdonefile = runMT.instdir+"/logs/nmapout."+customer+".done"; 

    String nmapcommand=runMT.instdir+"/bin/doscan.sh "+nmapoutfile+" "+IPRange+" "+nmapstatusfile+" "+nmapdonefile; 

    System.out.println(nmapcommand); 
    Runtime r = Runtime.getRuntime(); 
    Process pr = r.exec(nmapcommand); 
    try { 
     BufferedReader inbr = new BufferedReader (new FileReader(new File(nmapstatusfile)));   
    } 
    catch(Exception e){ 
     e.printStackTrace(); 
    } 
    while (inbr.readLine()!=null){ 
     System.out.println("Line is .. " + inbr.readLine()); 
    } 
    pr.waitFor(); 
} 

?? : 여기

내 코드입니다

+0

왜 지구상에하고 싶습니까? 이는 애플리케이션을 강제 스와핑하도록 프로그래밍하는 것과 거의 같습니다. –

+0

http://stackoverflow.com/questions/12818341/bufferedreader-readline-when-reading-in-a-thread – Batty

+0

리눅스를 사용하고 있다면 파일을 꼬리 수 있습니다 .. –

답변

관련 문제