java.io.PrintStream类的使用及代码示例

x33g5p2x  于2022-01-16 转载在 其他  
字(5.6k)|赞(0)|评价(0)|浏览(106)

本文整理了Java中java.io.PrintStream类的一些代码示例,展示了PrintStream类的具体用法。这些代码示例主要来源于Github/Stackoverflow/Maven等平台,是从一些精选项目中提取出来的代码,具有较强的参考意义,能在一定程度帮忙到你。PrintStream类的具体详情如下:
包路径:java.io.PrintStream
类名称:PrintStream

PrintStream介绍

[英]Fake signature of an existing Java class.
[中]现有Java类的伪签名。

代码示例

代码示例来源:origin: stackoverflow.com

for (Entry<String, List<String>> header : connection.getHeaderFields().entrySet()) {
  System.out.println(header.getKey() + "=" + header.getValue());
}

代码示例来源:origin: libgdx/libgdx

private void out (String message, int nesting) {
  for (int i = 0; i < nesting; i++)
    System.out.print("  ");
  System.out.println(message);
}

代码示例来源:origin: stackoverflow.com

private final ByteArrayOutputStream outContent = new ByteArrayOutputStream();
private final ByteArrayOutputStream errContent = new ByteArrayOutputStream();

@Before
public void setUpStreams() {
  System.setOut(new PrintStream(outContent));
  System.setErr(new PrintStream(errContent));
}

@After
public void cleanUpStreams() {
  System.setOut(null);
  System.setErr(null);
}

代码示例来源:origin: hankcs/HanLP

static void usage()
{
  System.err.printf("Usage: java %s <query-file> <k> <out-file>\n", WordCluster.class.getName());
  System.err.println("\t<query-file> contains word projections in the text format\n");
  System.err.println("\t<k> number of clustering\n");
  System.err.println("\t<out-file> output file\n");
  System.exit(0);
}

代码示例来源:origin: Tencent/tinker

public static void d(final String format, final Object... obj) {
  String log = obj.length == 0 ? format : String.format(format, obj);
  if (log == null) {
    log = "";
  }
  //add \n
  System.out.printf(log + "\n");
  System.out.flush();
  logWriter.writeLineToInfoFile(log);
}

代码示例来源:origin: stackoverflow.com

try (Scanner scanner = new Scanner(response)) {
  String responseBody = scanner.useDelimiter("\\A").next();
  System.out.println(responseBody);
}

代码示例来源:origin: crossoverJie/JCSprout

public static void main(String[] args) throws InterruptedException {
  Volatile aVolatile = new Volatile();
  new Thread(aVolatile,"thread A").start();
  System.out.println("main 线程正在运行") ;
  Scanner sc = new Scanner(System.in);
  while(sc.hasNext()){
    String value = sc.next();
    if(value.equals("1")){
      new Thread(new Runnable() {
        @Override
        public void run() {
          aVolatile.stopThread();
        }
      }).start();
      break ;
    }
  }
  System.out.println("主线程退出了!");
}

代码示例来源:origin: stackoverflow.com

Scanner reader = new Scanner(System.in);  // Reading from System.in
System.out.println("Enter a number: ");
int n = reader.nextInt(); // Scans the next token of the input as an int.

代码示例来源:origin: jenkinsci/jenkins

protected Process sudoWithPass(ArgumentListBuilder args) throws IOException {
    args.prepend(sudoExe(),"-S");
    listener.getLogger().println("$ "+Util.join(args.toList()," "));
    ProcessBuilder pb = new ProcessBuilder(args.toCommandArray());
    Process p = pb.start();
    // TODO: use -p to detect prompt
    // TODO: detect if the password didn't work
    PrintStream ps = new PrintStream(p.getOutputStream());
    ps.println(rootPassword);
    ps.println(rootPassword);
    ps.println(rootPassword);
    return p;
  }
}.start(listener,rootPassword);

代码示例来源:origin: iluwatar/java-design-patterns

@Override
 protected void printThisBefore() {
  System.out.print(c);
 }
}

代码示例来源:origin: hankcs/HanLP

public static void INFO_LOG(String format, Object ... args)
  {
    System.err.printf(format, args);
  }
}

代码示例来源:origin: eclipse-vertx/vert.x

private String record(Runnable runnable) {
 ByteArrayOutputStream stream = new ByteArrayOutputStream();
 PrintStream written = new PrintStream(stream);
 setStream(written);
 runnable.run();
 written.flush();
 String result = stream.toString();
 quiet(() -> {
  written.close();
  return null;
 });
 return result;
}

代码示例来源:origin: EnterpriseQualityCoding/FizzBuzzEnterpriseEdition

private void doFizzBuzz(final int n, final String s) throws IOException {
  final ByteArrayOutputStream baos = new ByteArrayOutputStream();
  final BufferedOutputStream bos = new BufferedOutputStream(baos);
  System.setOut(new PrintStream(bos));
  this.fb.fizzBuzz(n);
  System.out.flush();
  String platformDependentExpectedResult = s.replaceAll("\\n", System.getProperty("line.separator"));
  assertEquals(platformDependentExpectedResult, baos.toString());
}

代码示例来源: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: commons-io/commons-io

public static void checkWrite(final OutputStream output) throws Exception {
  try {
    new java.io.PrintStream(output).write(0);
  } catch (final Throwable t) {
    throw new AssertionFailedError(
        "The copy() method closed the stream "
            + "when it shouldn't have. "
            + t.getMessage());
  }
}

代码示例来源:origin: stackoverflow.com

String content = new Scanner(new File("filename")).useDelimiter("\\Z").next();
System.out.println(content);

代码示例来源:origin: iluwatar/java-design-patterns

@Override
 protected void printThisAfter() {
  System.out.print(".");
 }
}

代码示例来源:origin: hankcs/HanLP

private void printAccuracy(double[] accuracy)
{
  if (accuracy.length == 3)
  {
    out.printf("P:%.2f R:%.2f F:%.2f\n", accuracy[0], accuracy[1], accuracy[2]);
  }
  else
  {
    out.printf("P:%.2f\n", accuracy[0]);
  }
}

代码示例来源:origin: Tencent/tinker

public static void e(final String format, final Object... obj) {
  String log = obj.length == 0 ? format : String.format(format, obj);
  if (log == null) {
    log = "";
  }
  //add \n
  System.err.printf(log + "\n");
  System.err.flush();
  logWriter.writeLineToInfoFile(log);
}

代码示例来源:origin: stackoverflow.com

public class Test {
 public static void main(String[] args) {
  outerloop:
  for (int i=0; i < 5; i++) {
   for (int j=0; j < 5; j++) {
    if (i * j > 6) {
     System.out.println("Breaking");
     break outerloop;
    }
    System.out.println(i + " " + j);
   }
  }
  System.out.println("Done");
 }
}

相关文章