简体   繁体   English

NetBeans平台-从输出控制台打开文件

[英]NetBeans platform - open file from output console

I would like to open file specified by its path in NetBeans editor ( IOProvider.getDefault().getIO(...); ). 我想在NetBeans编辑器( IOProvider.getDefault().getIO(...); )中打开由其路径指定的文件。

I would like the same functionality as is when some Java/C/C++ or any other programming language prints an Exception. 我想要与某些Java / C / C ++或任何其他编程语言打印Exception时相同的功能。 As far as I went for now: 就我目前而言:

  1. Write the output in console (see the example at the end) 在控制台中写入输出(请参见最后的示例)
  2. By using OutputListener resolve what should be printed as hypertext 通过使用OutputListener解析应打印为超文本的内容
  3. OutputListener.outputLineAction that defines what to do when clicked on hypertext IOColorPrint.print(InputOutput io, CharSequence text, OutputListener listener, boolean important, Color color) 定义单击超文本IOColorPrint.print(InputOutput io, CharSequence text, OutputListener listener, boolean important, Color color)时的操作的IOColorPrint.print(InputOutput io, CharSequence text, OutputListener listener, boolean important, Color color)
  4. Open the file on the system when clicking on 单击时在系统上打开文件

An example of error message I need to resolve: 我需要解决的错误消息示例:

The export was successful. 导出成功。 The exported file can be found in: C:\\Users\\MY_USER\\Desktop\\myFile.xml 可以在以下位置找到导出的文件:C:\\ Users \\ MY_USER \\ Desktop \\ myFile.xml

The problem that I have is that I have to print all the output in one line and the OutputEvent gives me all the line. 我的问题是我必须将所有输出都打印在一行中,而OutputEvent会给我所有行。 Is there any way to get only the Highlited text (The path) ? 有什么方法可以只获取高亮文本(路径)吗?

This call open new console output tab: 该调用打开新的控制台输出选项卡:

IOProvider.getDefault().getIO(...)

You should take inputStream and use class while(x=is.read()!=n .... 您应该使用inputStream并使用while(x = is.read()!= n ....

IOProvider.getDefault().getIO(...).getInputStream

Let me know, if this was usefull. 让我知道是否有用。

Here the Listener : 这里的听众:

public class HyperlinkToFileOutputListener implements OutputListener {

private final File file;

public HyperlinkToFileOutputListener(File file) {
    this.file = file;
}

@Override
public void outputLineSelected(OutputEvent oe) {
}

@Override
public void outputLineAction(OutputEvent oe) {
    try {
        if (file.exists()) {
            Desktop.getDesktop().open(file);
        }
    } catch (IOException ex) {
        Exceptions.printStackTrace(ex);
    }

}

@Override
public void outputLineCleared(OutputEvent oe) {
}

} }

here the call 这里的电话

IOColorPrint.print(io, file.getName(), new HyperlinkToFileOutputListener(file), true, Color.BLUE);

best regards 最好的祝福

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

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM