2013-04-09 2 views
1

이것은 내 program.It "LTP"또는 "TRAILING"이라는 단어가 포함 된 문장을 인쇄해서는 안됩니다. 그러나 그 일은하지 않습니다. 왜 그런지 이해하지 못합니다. 제발 도와주세요.문자열 함수가 제대로 작동하지 않습니다

import java.io.*; 

public class FileInputDemo { 
    public static void main(String args[]) { 
     // args.length is equivalent to argc in C 
     try { 
      // Open the file that is the first 
      // command line parameter 
      FileInputStream fstream = new FileInputStream(
        "C:\\Documents and Settings\\work\\Desktop\\New Folder\\New Folder\\02Apr2013log1.txt"); 
      // Convert our input stream to a 
      // DataInputStream 
      DataInputStream in = new DataInputStream(fstream); 
      // Continue to read lines while 
      // there are still some left to read 
      while (in.available() != 0) { 
       String s=in.readLine(); 
       // Print file line to screen 
      if(s.startsWith("LTP") || s.contains("TRAILING")) 
      { 
       continue; 
      } 

      System.out.println(in.readLine()); 
      } 

      in.close(); 
     } catch (Exception e) { 
      System.err.println("File input error"); 
     } 
    } 
} 

그리고 이것은 출력

Long trade Managers in list (from Limit removal process) 2 
LTP 9708.0 Current Stop 9723.0 for Order ID BAA0001 Mode:- TRAILING 
9711.0 9716.0 9707.0 9707.0 9710.62 
BullishFactor [openBullishFactor=NEUTRAL, closeBullishfactor=BEARISH, closeToOpenFactor=MODERATE_BEARISH] 
BarSharing [sharingType=LLLH, bodySharing=0.44] 
LTP 9707.0 Current Stop 9717.0 for Order ID BAA0001 Mode:- TRAILING 
+0

으로 바꾸십시오. DataInputStream을 사용하여 텍스트를 읽지 마십시오. 또한 예제에서 제거하십시오.이 나쁜 아이디어는 자주 복사됩니다. http://vanillajava.blogspot.co.uk/2012/08/java-memes-which-refuse-to-die.html –

답변

0

System.out.println(in.readLine());에서 다시 읽지 마십시오. 다음 줄을 읽고 LTP | 선에서 TRAILING을 사용할 수 있습니다. System.out.println(s);

+1

OP의 말씨는 다소 혼란 스럽지만 * 단어로 시작하는 문장을 인쇄해야 함 ** "LTP"또는 "TRAILING"이라는 단어가 포함 된 문장 * –

+0

@JonLin 감사합니다. 나는 포스트를 감추고있는 동안 그 반대를 이해했다. 게시물을 편집합니다. 더 많은 커피가 필요합니다. ( –

+0

thanks.solved the problem..i shud b 인쇄 System.out.println 대신 System.out.println (in.readLine()). – maddy

3

System.out.println이 문자열 s을 인쇄 할 수 없습니다해야입니까?

while (in.available() != 0) { 
    String s=in.readLine(); 

    if(s.startsWith("LTP") || s.contains("TRAILING")) 
    { 
     continue; 
    } 

    System.out.println(s); 
} 

in.readLine()을 인쇄하는 경우는 라인 (s에 저장) 방금 읽은 한 후에 가능하다 "는 TRAILING"를 포함하거나 "LTP"로 시작합니다.

관련 문제