简体   繁体   English

如何在我的 Eclipse 中打印控制台值?

[英]How to print the console value in my Eclipse?

My Application is in some other folder, I call that function, the output is printed in my console.我的应用程序位于其他文件夹中,我称之为 function,output 打印在我的控制台中。

How can I get the value from the console?如何从控制台获取值?

I'm not sure if I understand the question.我不确定我是否理解这个问题。 However, you can use this code snippet to get line of text from console (it also works in Eclipse):但是,您可以使用此代码片段从控制台获取文本行(它也适用于 Eclipse):

String val = new BufferedReader(new InputStreamReader(System.in)).readLine();
System.out.println("val = " + val);

There is a way to redirect the console text into a log/text file under eclipse.有一种方法可以将控制台文本重定向到 eclipse 下的日志/文本文件中。 If you are running a web-based application, possibility is that you already have a.log file configured some where.如果您正在运行基于 Web 的应用程序,则可能是您已经在某个位置配置了 .log 文件。 You can simply open this log file and look for messages.您可以简单地打开此日志文件并查找消息。

In case of pure java application however, most of the output is showin in the eclipse console unless you configure a redirect.然而,在纯 java 应用程序的情况下,大多数 output 显示在 eclipse 控制台中,除非您配置重定向。

Pull up the "Debug" or "Run" dialogs where you configured your main class.拉起配置主 class 的“调试”或“运行”对话框。 Select the java application you want to run. Select 您要运行的 java 应用程序。 If you dont have an entry under "java applications", you might have to create one.如果您在“java 应用程序”下没有条目,您可能需要创建一个。 On the right hand side of the screen, select the "Common" tab.在屏幕的右侧,select 是“常用”选项卡。 Check the "File" checkbox and mention a physical path+filename in the input textbox.选中“文件”复选框并在输入文本框中提及物理路径+文件名。 You are all set.你都准备好了。 Open the specified file in your fav text editor.在您的收藏夹文本编辑器中打开指定的文件。

You select the text in your console, right-click and select copy.你把select的文本在你的控制台中,右击select复制。

Now you can paste the text you've copied.现在您可以粘贴已复制的文本。

Your function may be using System.out.println() to print out a variable to the console.您的 function 可能正在使用System.out.println()将变量打印到控制台。 To get this value from your function, you need to make your function return it eg要从您的 function 中获取此值,您需要让您的 function 返回它,例如

public int myFunction(){
   int val=42;
   System.out.println(val);
   return val;
}

//call it like this:
int result = myFunction();

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

相关问题 如何使用 selenium 捕获数据层 object 并在我的 eclipse 控制台中打印 - How to capture datalayer object and print in my eclipse console using selenium 如何在Eclipse的调试控制台中打印Java对象的当前值? - How to print Java object's current value in debug console in Eclipse? 如何在Eclipse中打印到textArea而不是控制台? - How to print to textArea instead of console in eclipse? 如何在 Eclipse 的控制台中打印唯一的 ASCII? - How to print unique ASCII in Eclipse's console? 如何将[简体]汉字打印到Eclipse控制台? - How to print [Simplified] Chinese characters to Eclipse console? Eclipse中的Tomcat控制台输出:我的System.out.print()输出在哪里,如何调试? - Tomcat console output in Eclipse: where is my System.out.print() output, how to debug? 如何在 Eclipse 中调试时将 Java 对象的当前值打印到控制台,而不是挂起线程? - How to print Java object's current value to console, instead of suspend thread while debug in the Eclipse? 如何在我的控制台中打印 arraylist 的内容 - how to print content of arraylist in my console 如何获得Eclipse控制台以从DLL打印消息? - How can I get the Eclipse console to print messages from a DLL? 如何在GUI文本框而不是Eclipse控制台上打印输出? - How to print an output on GUI textbox instead of Eclipse console?
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM