JAVA:如何从首选项页面访问文件路径并在编程代码中使用它
内容导读
互联网集市收集整理的这篇技术教程文章主要介绍了JAVA:如何从首选项页面访问文件路径并在编程代码中使用它,小编现在分享给大家,供广大互联网技能从业者学习和参考。文章包含3123字,纯文字阅读大概需要5分钟。
内容图文
我的ProcessBuilder类—
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
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包中,
现在建议我访问的方式.
解决方法:
在构建ProcessBuilder的try-block中尝试这个:
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:如何从首选项页面访问文件路径并在编程代码中使用它所遇到的程序开发问题。 如果觉得互联网集市技术教程内容还不错,欢迎将互联网集市网站推荐给程序员好友。
内容备注
版权声明:本文内容由互联网用户自发贡献,该文观点与技术仅代表作者本人。本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如发现本站有涉嫌侵权/违法违规的内容, 请发送邮件至 gblab@vip.qq.com 举报,一经查实,本站将立刻删除。
内容手机端
扫描二维码推送至手机访问。