JAVA : How to access file path from preference page and use it in Programming code(JAVA:如何从首选项页面访问文件路径并在编程代码中使用它)
问题描述
我的 ProcessBuilder 类 ---
My ProcessBuilder class ---
public class HelloWorldAction implements IWorkbenchWindowActionDelegate {
IWorkbenchWindow activeWindow = null;
public void run(IAction proxyAction) {
MessageConsole myConsole = null;
String name = "outputConsole";
ConsolePlugin plugin = ConsolePlugin.getDefault();
IConsoleManager conMan = plugin.getConsoleManager();
IConsole[] existing = conMan.getConsoles();
for (int i = 0; i < existing.length; i++)
if (name.equals(existing[i].getName()))
myConsole = (MessageConsole) existing[i];
//no console found, so create a new one
if (myConsole == null)
myConsole = new MessageConsole(name, null);
conMan.addConsoles(new IConsole[]{myConsole});
IWorkbench wb = PlatformUI.getWorkbench();
IWorkbenchWindow win = wb.getActiveWorkbenchWindow();
IWorkbenchPage page = win.getActivePage();
String id = IConsoleConstants.ID_CONSOLE_VIEW;
try
{
IConsoleView view = (IConsoleView) page.showView(id);
view.display(myConsole);
}
catch (Exception e)
{
}
MessageConsoleStream out = myConsole.newMessageStream();
out.println("Prism Button Works !");
try { //to clear the console on every click of button
IViewPart view = PlatformUI.getWorkbench().getActiveWorkbenchWindow().getActivePage().findView(IConsoleConstants.ID_CONSOLE_VIEW);
if (view != null) {
(myConsole).clearConsole();
}
ProcessBuilder pb=new ProcessBuilder("C:\Program Files\prism-4.0\bin\prism.bat");
pb.directory(new File("C:\Program Files\prism-4.0\bin"));
Process p=pb.start();
BufferedReader input = new BufferedReader(new InputStreamReader(p.getInputStream()));
String in;
while((in = input.readLine()) != null) {
out.println(in);
}
int exitVal=p.waitFor();
if(exitVal==0)
{
out.println("Printing on console");
}
else
out.println("Process failed");
}
catch (Exception e)
{
out.println(e.toString());
e.printStackTrace();
}
}
// IActionDelegate method
public void selectionChanged(IAction proxyAction, ISelection selection) {
// do nothing, action is not dependent on the selection
}
// IWorkbenchWindowActionDelegate method
public void init(IWorkbenchWindow window) {
activeWindow = window;
}
// IWorkbenchWindowActionDelegate method
public void dispose() {
// nothing to do
}
}
我的 FileFieldEditorClass
My FileFieldEditorClass
public class SAML
extends FieldEditorPreferencePage
implements IWorkbenchPreferencePage {
public SAML() {
super(GRID);
setPreferenceStore(RmpPlugin.getDefault().getPreferenceStore());
setDescription("Browse Appropriate files");
}
public FileFieldEditor f;
public FileFieldEditor f1;
public void createFieldEditors() {
f=new FileFieldEditor(PreferenceConstants.P_PATH,
"&Prism.bat File:", getFieldEditorParent());
addField(f);
f1=new FileFieldEditor(PreferenceConstants.P_PATH1,
"&NuSMV Application File:", getFieldEditorParent());
addField(f1);
}
public void init(IWorkbench workbench) {
}
}
FileFieldEditor 类在 com.myplugin.rmp.preferences 包中并且 ProcessBuilder 类在 com.myplugin.rmp 包中,
FileFieldEditor class is in com.myplugin.rmp.preferences package and ProcessBuilder class is in com.myplugin.rmp package,
现在建议我访问的方式.
Now suggest me the way to way to access.
推荐答案
在你构建 ProcessBuilder 的 try-block 中试试这个:
Try this inside your try-block where you construct your ProcessBuilder:
IPreferenceStore store = plugin.getPreferenceStore();
ProcessBuilder pb=new ProcessBuilder(store.getString(PreferenceConstants.P_PATH);
pb.directory(new File(store.getString(PreferenceConstants.P_PATH1));
Process p=pb.start();
这篇关于JAVA:如何从首选项页面访问文件路径并在编程代码中使用它的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持编程学习网!
本文标题为:JAVA:如何从首选项页面访问文件路径并在编程代码中使用它
基础教程推荐
- “未找到匹配项"使用 matcher 的 group 方法时 2022-01-01
- Java Keytool 导入证书后出错,"keytool error: java.io.FileNotFoundException &拒绝访问" 2022-01-01
- 降序排序:Java Map 2022-01-01
- 减少 JVM 暂停时间 >1 秒使用 UseConcMarkSweepGC 2022-01-01
- 设置 bean 时出现 Nullpointerexception 2022-01-01
- 如何使用 Java 创建 X509 证书? 2022-01-01
- 无法使用修饰符“public final"访问 java.util.Ha 2022-01-01
- FirebaseListAdapter 不推送聊天应用程序的单个项目 - Firebase-Ui 3.1 2022-01-01
- Java:带有char数组的println给出乱码 2022-01-01
- 在 Libgdx 中处理屏幕的正确方法 2022-01-01