Remove Volume Information lines from dir command using java
I get this output from dir /a C:\Information\DataTransformation\externLibs\system
Volume in drive C has no label.
Volume Serial Number is 1878-D614
Directory of C:\Information\DataTransformation\externLibs\system开发者_开发知识库
08/23/2011 09:52 PM <DIR> .
08/23/2011 09:52 PM <DIR> ..
08/23/2011 09:52 PM 196,608 AFPtoXML_DP.dll
08/23/2011 09:52 PM 13,259 ASN1toXSDRunner.jar
08/23/2011 09:52 PM <DIR> birt
08/23/2011 09:52 PM 8,192 CM_CreateUUID.dll
08/23/2011 09:52 PM 19,456 EdifactValidation.dll
08/23/2011 09:52 PM 60,145 EDIValidator.jar
08/23/2011 09:52 PM 20,159 Excel2007ToDataXml.jar
08/23/2011 09:52 PM 217,088 ExcelToHtml.dll
08/23/2011 09:52 PM 192,512 ExcelToTxt.dll
08/23/2011 09:52 PM 541,646 ExcelToXml.jar
08/23/2011 09:52 PM 23,401 ExcelToXmlDataOnly.jar
08/23/2011 09:52 PM 10,032 ExcelToXml_03_07_10.jar
08/23/2011 09:52 PM 8,192 guid_transformer.dll
08/23/2011 09:52 PM 9,216 hebAsciiBidiKH.dll
08/23/2011 09:52 PM 40,960 hebAsciiBidiMoz.dll
08/23/2011 09:52 PM <DIR> HIPAAValidation
08/23/2011 09:52 PM 21,921 HIPAAValidation.jar
08/23/2011 09:52 PM 1,613 IBANValidator.jar
08/23/2011 09:52 PM 4,641 loader.jar
08/23/2011 09:52 PM 24,576 MSMQ.dll
08/23/2011 09:52 PM 24,576 MSMQOutput.dll
08/23/2011 09:52 PM 28,672 ODBC.dll
08/23/2011 09:52 PM 209,563 OfficeToXml.jar
08/23/2011 09:52 PM 17,408 PdfFormToXml_1_00_DP.dll
08/23/2011 09:53 PM <DIR> PDFLanguages
08/23/2011 09:52 PM 286,720 PdfToTxt2_3_02_07_DP.dll
08/23/2011 09:52 PM 409,600 PdfToTxt_2_02.dll
08/23/2011 09:52 PM 528,384 PdfToTxt_3_00_DP.dll
08/23/2011 09:52 PM 634,880 PdfToTxt_3_02_DP.dll
08/23/2011 09:52 PM <DIR> poi
08/23/2011 09:52 PM 24,576 PowerpointToHTML.dll
08/23/2011 09:52 PM 13,643 PptToXml.jar
08/23/2011 09:52 PM 1,487 Regex1_4.jar
08/23/2011 09:52 PM 29,696 RtfToTxt_DP.dll
08/23/2011 09:52 PM 217,088 WordToHtml.dll
08/23/2011 09:52 PM 188,416 WordToRtf.dll
08/23/2011 09:52 PM 188,416 WordToTxt.dll
08/23/2011 09:52 PM 305,428 WordToXml.jar
08/23/2011 09:52 PM 73,728 WpToTxt_DP.dll
08/23/2011 09:52 PM 19,456 X12EDIValidation.dll
08/23/2011 09:52 PM 927,669 xercesImpl.jar
08/23/2011 09:52 PM 115,701 xercesSamples.jar
08/23/2011 09:52 PM 123,705 xml-apis.jar
08/23/2011 09:52 PM 123,705 xmlParserAPIs.jar
08/23/2011 09:52 PM 8,786 XmlToBirtPP.jar
08/23/2011 09:52 PM 671,744 XpdfText.dll
42 File(s) 6,586,664 bytes
6 Dir(s) 15,978,725,376 bytes free
I want to remove the below lines from output
Volume in drive C has no label.
Volume Serial Number is 1878-D614
Directory of C:\Information\DataTransformation\externLibs\system
My Code
def externalLibrarySystem(csm,pluginOutputs)
{
String rs = (String)pluginOutputs.get("ExternalLibrarySystem")
String temp=rs
csm.externalLibrarySystem(rs)
{
"${rs}"
}
}
Note: temp has the dir output
In Java you use the Scanner class. Copy line for line to a StringBuilder. Have a int counter and don't append the first 5 lines.
String rs = (String)pluginOutputs.get("ExternalLibrarySystem");
StringBuilder sb = new StringBuilder();
Scanner sc = new Scanner(rs);
int cnt = 0;
while (sc.hasNextLine()) {
if(cnt>4){
sb.append(sc.nextLine()+System.getProperty("line.separator"));
}
cnt++;
}
String temp = sb.toString();
精彩评论