我怎样才能将Java控制台输出读入String缓冲区

我有一个Java程序,可以将一些文本输出到控制台。 它使用print , println和其他一些方法来完成此操作。 在程序结束时,我想读取控制台中的所有文本并将其复制到String缓冲区中。 我怎么能用Java做到这一点? 我需要分别阅读stdout和stderr 。

为什么List 不能作为List ?

考虑下面的方法doSomething(List)接受List作为参数。 private void doSomething(List list) { // do something } 现在考虑下面的代码片段,它尝试调用doSomething() ,我尝试将List传递给doSomething() List objectList; List stringList; doSomething(stringList); // compilation error incompatible types doSomething(objectList); // works fine 即使在代码下面也会引发编译错误 objectList = stringList; // compilation error incompatible types 我的问题是为什么List无法传递给接受List ?

在Java中重定向stdin和stdout

我正在尝试重定向java中的子进程的stdin和stdout,最终我将输出转到JTextArea或其他东西。 这是我目前的代码, Process cmd = Runtime.getRuntime().exec(“cmd.exe”); cmd.getOutputStream().write(“echo Hello World”.getBytes()); cmd.getOutputStream().flush(); byte[] buffer = new byte[1024]; cmd.getInputStream().read(buffer); String s = new String(buffer); System.out.println(s); 输出如下: Microsoft Windows [Version 6.1.7601] Copyright (c) 2009 Microsoft Corporation. All rights reserved. C:\(Current Directory)> 我期待看到输出的“Hello World”字符串。 也许是因为父母的过程没有长久存活? 我也希望能够发送和接收多个命令。

如何计算二叉搜索树的深度

我想计算二进制搜索树的每个节点的深度的总和。 元素的各个深度尚未存储。

如何在Java中将TIF转换为PNG?

在Java下,将TIF文件转换为PNG的最佳方法是什么? 简单是可取的,但如果最简单的方法是使用第三方库,那么我会考虑这个解决方案。

java indexof(String str)方法复杂度

可能重复: String.indexof()函数调用的成本/复杂性是多少? java indexof(String str)方法的复杂性是什么? 我的意思是有像KMP这样的字符串匹配算法,它们在线性时间内运行。 我正在实现一个需要在一个非常大的字符串中搜索大子字符串的系统,所以我可以使用java indexof(String str)方法,或者我应该实现KMP。

解压缩BZIP2存档

我可以解压缩zip,gzip和rar文件,但我还需要解压缩bzip2文件以及解压缩它们(.tar)。 我没有遇到过一个好的图书馆。 我正在使用Java和Maven,所以理想情况下,我想将它作为POM中的依赖项包含在内。 你推荐哪些图书馆?

GWT RequestBuilder – 跨站请求

我正在尝试使用GWT请求构建器创建跨站点请求,我无法使其工作。 正如您所看到的,这是一个样本GWT项目,我已经浏览了https://developers.google.com/web-toolkit/doc/latest/tutorial/Xsite 。 但我仍然缺少一些东西。 我在这里发布代码。 我错过了什么..? package com.gwt.reqbuilder.client; import com.google.gwt.core.client.EntryPoint; import com.google.gwt.http.client.Request; import com.google.gwt.http.client.RequestBuilder; import com.google.gwt.http.client.RequestCallback; import com.google.gwt.http.client.RequestException; import com.google.gwt.http.client.Response; import com.google.gwt.http.client.URL; import com.google.gwt.user.client.Window; public class GWTRequestBuilder implements EntryPoint { private static final String JSON_URL = “http://localhost:8000/?q=ABC&callback=callback125″; public void onModuleLoad() { GWTPOSTHTTP(); } public void GWTPOSTHTTP() { String postUrl=”http://localhost:8000″; String requestData=”q=ABC&callback=callback125”; RequestBuilder builder = new […]

Javafx使用计时器时不在fx应用程序线程上

我正在使用这个 import java.util.Random; import java.util.Timer; import java.util.TimerTask; import javafx.application.Application; import javafx.application.Platform; import javafx.scene.Group; import javafx.scene.Scene; import javafx.scene.paint.Color; import javafx.scene.shape.Circle; import javafx.stage.Stage; public class Main extends Application { public static void main(String[] args) { launch(args); } @Override public void start(Stage primaryStage) { Group root = new Group(); Scene scene = new Scene(root, 600, 400); primaryStage.setScene(scene); Circle […]

具有注释参数的切入点匹配方法

在以下情况下,我需要使用与方法匹配的切入点创建方面: 它是用MyAnnotationForMethod注释的 其中一个参数(可以有很多)用@MyAnnotationForParam注释(但也可以有其他注释)。 方面类看起来像这样 @Pointcut(“execution(@MyAnnotationForMethod * *(..,@aspects.MyAnnotationForParam Object, ..)) && args(obj)”) void myPointcut(JoinPoint thisJoinPoint, Object obj) { } @Before(“myPointcut(thisJoinPoint , obj)”) public void doStuffOnParam(JoinPoint thisJoinPoint, Object obj) { LOGGER.info(“doStuffOnParam :”+obj); } 注释方法 @MyAnnotationForMethod public string theMethod(String a, @MyAnnotationForParam @OtherAnnotation Object obj, Object b){ LOGGER.info(a+obj+b); } 随着eclipse – >警告:关于poincut: Multiple markers at this line – no […]