本文整理了Java中java.io.PrintStream.close()
方法的一些代码示例,展示了PrintStream.close()
的具体用法。这些代码示例主要来源于Github
/Stackoverflow
/Maven
等平台,是从一些精选项目中提取出来的代码,具有较强的参考意义,能在一定程度帮忙到你。PrintStream.close()
方法的具体详情如下:
包路径:java.io.PrintStream
类名称:PrintStream
方法名:close
[英]Closes this print stream. Flushes this stream and then closes the target stream. If an I/O error occurs, this stream's error state is set to true.
[中]关闭此打印流。刷新此流,然后关闭目标流。如果发生I/O错误,则此流的错误状态设置为true。
代码示例来源:origin: Alluxio/alluxio
private String stacktrace(Exception e) {
ByteArrayOutputStream os = new ByteArrayOutputStream();
PrintStream ps = new PrintStream(os, true);
e.printStackTrace(ps);
ps.close();
return os.toString();
}
}
代码示例来源:origin: stackoverflow.com
File file = new File("test.log");
PrintStream ps = new PrintStream(file);
try {
// something
} catch (Exception ex) {
ex.printStackTrace(ps);
}
ps.close();
代码示例来源:origin: stackoverflow.com
final OutputStream os = new FileOutputStream("/tmp/out");
final PrintStream printStream = new PrintStream(os);
printStream.print("String");
printStream.close();
代码示例来源:origin: java-json-tools/json-schema-validator
optionSet = parser.parse(args);
} catch (OptionException e) {
System.err.println("unrecognized option(s): "
+ CustomHelpFormatter.OPTIONS_JOINER.join(e.options()));
parser.printHelpOn(System.err);
System.err.println("cannot specify both \"--brief\" and " +
"\"--quiet\"");
parser.printHelpOn(System.err);
System.err.println("missing arguments");
parser.printHelpOn(System.err);
System.exit(CMD_ERROR.get());
files.add(new File(target).getCanonicalFile());
System.out.close();
System.err.close();
reporter = Reporters.QUIET;
代码示例来源:origin: libgdx/libgdx
PrintStream out = new PrintStream(file, "UTF-8");
out.println("font.name=" + fontName);
out.println("font.size=" + fontSize);
out.println("font.bold=" + bold);
out.println("font.italic=" + italic);
out.println("font.gamma=" + gamma);
out.println();
out.close();
代码示例来源:origin: syncany/syncany
private int showErrorAndExit(String errorMessage) {
out.println("Error: " + errorMessage);
out.println(" Refer to help page using '--help'.");
out.println();
out.close();
return 1;
}
}
代码示例来源:origin: cmusphinx/sphinx4
/**
* Dumps the config as a set of HTML tables
*
* @param ConfigurationManager the manager
* @param path where to output the HTML
* @throws java.io.IOException if an error occurs
*/
public static void showConfigAsHTML(ConfigurationManager ConfigurationManager, String path) throws IOException {
PrintStream out = new PrintStream(new FileOutputStream(path));
dumpHeader(out);
for (String componentName : ConfigurationManager.getInstanceNames(Configurable.class)) {
dumpComponentAsHTML(out, componentName, ConfigurationManager.getPropertySheet(componentName));
}
dumpFooter(out);
out.close();
}
代码示例来源:origin: geoserver/geoserver
@Test
public void testFlushOnClose() throws IOException {
MockHttpServletResponse mockResponse = new MockHttpServletResponse();
PartialBufferedOutputStream2 pbos = new PartialBufferedOutputStream2(mockResponse);
PrintStream ps = new PrintStream(pbos);
ps.print("Hello world!");
ps.close();
// check the in memory buffer has been flushed to the target output stream
// close
assertEquals("Hello world!", mockResponse.getContentAsString());
}
}
代码示例来源:origin: apache/incubator-pinot
@Override
public void copyFromLocalFile(File srcFile, URI dstUri)
throws Exception {
OutputStream stream = _adlStoreClient.createFile(dstUri.getPath(), IfExists.OVERWRITE);
PrintStream out = new PrintStream(stream);
byte[] inputStream = IOUtils.toByteArray(new FileInputStream(srcFile));
out.write(inputStream);
out.close();
}
代码示例来源:origin: cmusphinx/sphinx4
/**
* Creates the individual batch files
*
* @param dir the directory to place the input file in
* @param name the name of the file
* @param line the contents of the file
*/
private void createInputFile(File dir, String name, String line)
throws IOException {
File path = new File(dir, name);
FileOutputStream fos = new FileOutputStream(path);
PrintStream ps = new PrintStream(fos);
ps.println(line);
ps.close();
}
代码示例来源:origin: stackoverflow.com
public static String exceptionStacktraceToString(Exception e)
{
ByteArrayOutputStream baos = new ByteArrayOutputStream();
PrintStream ps = new PrintStream(baos);
e.printStackTrace(ps);
ps.close();
return baos.toString();
}
代码示例来源:origin: sarxos/webcam-capture
private void caugh(Throwable t) {
File f = new File(String.format("webcam-capture-hs-%s", System.currentTimeMillis()));
PrintStream ps = null;
try {
t.printStackTrace(ps = new PrintStream(f));
} catch (FileNotFoundException e) {
e.printStackTrace();
} finally {
if (ps != null) {
ps.close();
}
}
}
代码示例来源:origin: libgdx/libgdx
PrintStream out = new PrintStream(file, "UTF-8");
out.println("font.name=" + fontName);
out.println("font.size=" + fontSize);
out.println("font.bold=" + bold);
out.println("font.italic=" + italic);
out.println("font.gamma=" + gamma);
out.println();
out.close();
代码示例来源:origin: syncany/syncany
private int printHelpTextAndExit(String helpTextResource) throws IOException {
String fullHelpTextResource = HELP_TEXT_RESOURCE_ROOT + helpTextResource;
InputStream helpTextInputStream = CommandLineClient.class.getResourceAsStream(fullHelpTextResource);
if (helpTextInputStream == null) {
return showErrorAndExit("No detailed help text available for this command.");
}
for (String line : IOUtils.readLines(helpTextInputStream)) {
line = replaceVariables(line);
out.println(line.replaceAll("\\s$", ""));
}
out.close();
return 0;
}
代码示例来源:origin: apache/kylin
@Test
public void testGetProperty() throws IOException {
PrintStream o = System.out;
File f = File.createTempFile("cfg", ".tmp");
PrintStream tmpOut = new PrintStream(new FileOutputStream(f), false, "UTF-8");
System.setOut(tmpOut);
KylinConfigCLI.main(new String[] { "kylin.storage.url" });
String val = FileUtils.readFileToString(f, Charset.defaultCharset()).trim();
assertEquals("hbase", val);
tmpOut.close();
FileUtils.forceDelete(f);
System.setOut(o);
}
代码示例来源:origin: org.apache.ant/ant
/**
* Execute the length task.
*/
@Override
public void execute() {
validate();
OutputStream out =
property == null ? new LogOutputStream(this, Project.MSG_INFO)
: new PropertyOutputStream(getProject(), property);
PrintStream ps = new PrintStream(out);
switch (mode) {
case STRING:
ps.print(getLength(string, getTrim()));
ps.close();
break;
case EACH:
handleResources(new EachHandler(ps));
break;
case ALL:
handleResources(new AllHandler(ps));
break;
}
}
代码示例来源:origin: stackoverflow.com
public static void main(String args[]) throws IOException {
PrintStream ps = null;
try {
ps = new PrintStream(new FileOutputStream("myfile.txt"));
ps.println("This data is written to a file:");
System.out.println("Write successfully");
} catch (IOException e) {
System.err.println("Error in writing to file");
throw e;
} finally {
if (ps != null) ps.close();
}
}
代码示例来源:origin: jenkinsci/jenkins
/**
* Get long description as a string.
*/
@Restricted(NoExternalUse.class)
public final String getLongDescription() {
ByteArrayOutputStream out = new ByteArrayOutputStream();
PrintStream ps = new PrintStream(out);
printUsageSummary(ps);
ps.close();
return out.toString();
}
代码示例来源:origin: neo4j/neo4j
public static void dumpVmInfo( File directory ) throws IOException
{
File file = new File( directory, "main-vm-dump-" + System.currentTimeMillis() );
PrintStream out = null;
try
{
out = new PrintStream( file );
dumpVmInfo( out );
}
finally
{
if ( out != null )
{
out.close();
}
}
}
代码示例来源:origin: apache/flink
tempFile.setWritable(true);
PrintStream ps = new PrintStream(tempFile);
ps.println(first);
ps.println(second);
ps.close();
System.err.println("test failed with exception: " + t.getMessage());
t.printStackTrace(System.err);
fail("Test erroneous");
内容来源于网络,如有侵权,请联系作者删除!