如果你有一个java.io.InputStream对象,你应该如何处理该对象并产生一个String?
假设我有一个InputStream包含文本数据,并且我想将其转换为a String,所以例如我可以将其写入日志文件.
采取InputStream并将其转换为最简单的方法是String什么?
public String convertStreamToString(InputStream is) {
// ???
}
Run Code Online (Sandbox Code Playgroud) 我正在尝试获取有关系统上打印机的一些信息.
在Windows和Linux上,使用此代码,仅PrinterName填充属性:
PrintService[] printServices = PrintServiceLookup.lookupPrintServices(null,null);
for( PrintService printService : printServices ) {
log.info("Found print service: "+printService);
log.info(printService.getAttribute(PrinterName.class));
log.info(printService.getAttribute(PrinterLocation.class));
log.info(printService.getAttribute(PrinterMakeAndModel.class));
log.info(printService.getAttribute(PrinterMessageFromOperator.class));
log.info(printService.getAttribute(PrinterMoreInfo.class));
log.info(printService.getAttribute(PrinterMoreInfoManufacturer.class));
log.info(printService.getAttribute(PrinterState.class));
log.info(printService.getAttribute(PrinterStateReasons.class));
log.info(printService.getAttribute(PrinterURI.class));
}
Run Code Online (Sandbox Code Playgroud)
使用toArray()它后的功能......
log.info("Found print service: "+printService);
for( Attribute a : printService.getAttributes().toArray() ) {
log.info("* "+a.getName()+": "+a);
}
Run Code Online (Sandbox Code Playgroud)
......这是结果:
Found print service: Win32 Printer : Brother MFC-9420CN BR-Script3 * color-supported: supported * printer-name: Brother MFC-9420CN BR-Script3 * printer-is-accepting-jobs: accepting-jobs * queued-job-count: 0
如何获取更多信息,例如打印机评论?