"silent.txt"라는 파일이 있습니다. 나는이를 어떻게 그루비 스크립트를 사용groovy를 사용하여 파일에서 문자열 바꾸기
bop4InstallDir = "/abc/xyz/pqr"
와 위의 텍스트를 대체 할
bop4InstallDir = myProps.cordys_install_dir + "/" + instanceName
을 다음과 같이이 파일은 라인을 가지고있다? 도와주세요.
"silent.txt"라는 파일이 있습니다. 나는이를 어떻게 그루비 스크립트를 사용groovy를 사용하여 파일에서 문자열 바꾸기
bop4InstallDir = "/abc/xyz/pqr"
와 위의 텍스트를 대체 할
bop4InstallDir = myProps.cordys_install_dir + "/" + instanceName
을 다음과 같이이 파일은 라인을 가지고있다? 도와주세요.
다음 코드는 작동 :
def file = new File("silent.txt")
def fileText = file.replaceAll("bop4InstallDir\\ \\=\\ myProps.cordys_install_dir\\ \\+\\ \"\\/\"\\ \\+\\ instanceName", "bop4InstallDir\\ \\=\\ \"/opt/cordys/bop4/defaultInst1\"")
file.write(fileText);
별로 좋지는 않지만 제대로 작동합니다.
def file = new File("silent.txt")
file.text = file.text.replace('bop4InstallDir = myProps.cordys_install_dir + "/" + instanceName',
'bop4InstallDir = "/abc/xyz/pqr"')
silent.txt 형식이 올바른 등록 정보 파일입니까? 이 경우 다양한 방법으로 액세스 할 수 있으며 바보 대체보다 훨씬 안전합니다.
봐는 groovy: How to access to properties file? 또는 ConfigSlurper
속성 파일이 아닙니다. 그것의 그루비 스크립트. – user3291679
그것이 작동하지 않습니다. 오류는 "EOF를 찾았습니다. ')'@ 6 행 34 행입니다. 'bop4InstallDir ="/ abc/xyz/pqr "')" – user3291679
따옴표를 잘못 입력했다고 생각합니다. 위의 코드를 그대로 복사 한 다음 시도하십시오. – kunal
복사 된 코드가 작동하지 않았습니다. 나는 '/', '+'와 같은 특수 문자와 관련이 있습니다 ... – user3291679