-3

내가이 스크립트를하고 난 줄특정 라인

#! /bin/sh 
# ================================================================== 
# ______       __  _____ 
# /_ __/___ ____ ___ _________ _/ /_ /__/
#///__ \/ __ `__ \/ ___/ __ `/ __/ // 
#////_/////// /__/ /_///_ // 
#/_/ \____/_/ /_/ /_/\___/\__,_/\__/  /_/ 

HDK 
# Multi-instance Apache Tomcat installation with a focus 
# on best-practices as defined by Apache, SpringSource, and MuleSoft 
# and enterprise use with large-scale deployments. 
# Credits: 
#  Google -> Couldn't survive without it 
#  Stackoverflow.com -> Community support 
#  SpringSource -> Specifically best-practices and seminars (Expert Series) 
SDK 
# Based On: 
#  http://www.springsource.com/files/uploads/tomcat/tomcatx-performance-tuning.pdf 
http://www.springsource.com/files/u1/PerformanceTuningApacheTomcat-Part2.pdf 
#  http://www.springsource.com/files/uploads/tomcat/tomcatx-large-scale-deployments.pdf 

당 SDK 텍스트 라인과 라인에 도움을 주시기 바랍니다 HDK 텍스트 라인에서 라인을 추출 할로 시작하는 파일을 읽어보세요! 내가

public class ScannerExample { 

public static void main(String args[]) throws FileNotFoundException { 

    //creating File instance to reference text file in Java 
    File text = new File("E:\\file.txt"); 

    //Creating Scanner instnace to read File in Java 
    Scanner scnr = new Scanner(text); 

    //Reading each line of file using Scanner class 
    int lineNumber = 1; 
    int lineNumber1 = 1; 
    int numinf = 1; 
    int numsup=1; 

    while(scnr.hasNextLine()){ 
     String line = scnr.nextLine(); 
     if (line.contains("HDK")){numinf=lineNumber; 
     System.out.println(numinf); 
    } 

     if (line.contains("SDK")){numsup=lineNumber; 
     System.out.println(numsup);} 


     lineNumber++; 
    } 
    Scanner scnr1 = new Scanner(text); 

    while(scnr1.hasNextLine()){ 
     String line = scnr.nextLine(); 
     if (lineNumber>numinf){ 
     System.out.println("line " + lineNumber + " :" + line);} 
     lineNumber1++; 
    }  

    } 



    } 

을 시도했지만 그것은 작동하지 않았고 난이 메도보다 더 사용하여 파일을 탐색 묶고 내가 바란 영역에서 readnig을 제한 할 수 있습니다!

+3

StackOverflow에 오신 것을 환영합니다. 코드를 묻는 질문은 해결 된 문제에 대해 최소한의 이해를 보여 주어야합니다. 시도한 해결책, 실패한 이유 및 예상되는 결과를 포함시킵니다. 또한 : [Stack Overflow question checklist] (http://meta.stackexchange.com/questions/156810/stack-overflow-question-checklist) –

답변

0

나는 당신이 직면하고있는 문제가 무엇인지 정확히 알지 못합니다. scnr1.nextLine에
하지만 코드에서 문제를 볼 수 있습니다

while(scnr1.hasNextLine()){ 
     String line = scnr.nextLine();//this line is a problem 
     if (lineNumber>numinf){ 
     System.out.println("line " + lineNumber + " :" + line);} 
     lineNumber1++; 
    } 

변경 scnr.nextLine는()()
은 당신의 코드가 실행 얻을 것이다.

+0

줄 번호 = numinf에서 읽는 것을 시작하고 싶습니다. = scnr.nextline() – user2592651

+0

scnr 참조에서 읽기를 완료 했으므로 scnr을 사용하여 두 번째 스캐너 루프를 읽으려고하면 코드에 예외가 생깁니다. 그래서 내가 이해 한 것은 완전한 해결책이 필요하다는 것입니다. –

관련 문제