Java 使用将被调用回程序的字典程序调用翻译程序
我是一个完全不懂编码的人,我想知道我是否能得到一些帮助 我有这个项目,基本上我需要做的是: 创建2个可执行程序。翻译程序和字典程序。这些程序可以用任何语言编写 翻译程序将向词典程序传递一个英语单词。字典程序将翻译并返回一个外来词。翻译程序将打印出英文单词并将其翻译成文件 字典程序将查找英文单词并返回其外文翻译。词典程序将能够将选定数量的英语单词翻译成另一种语言。词典程序翻译英语单词的语言将由学生决定。字典程序将有能力将至少15个英语单词翻译成外语 现在我很难让字典程序调用翻译程序。 我的指导老师告诉我们使用这个语句Java 使用将被调用回程序的字典程序调用翻译程序,java,process,jar,inputstream,runtime.exec,Java,Process,Jar,Inputstream,Runtime.exec,我是一个完全不懂编码的人,我想知道我是否能得到一些帮助 我有这个项目,基本上我需要做的是: 创建2个可执行程序。翻译程序和字典程序。这些程序可以用任何语言编写 翻译程序将向词典程序传递一个英语单词。字典程序将翻译并返回一个外来词。翻译程序将打印出英文单词并将其翻译成文件 字典程序将查找英文单词并返回其外文翻译。词典程序将能够将选定数量的英语单词翻译成另一种语言。词典程序翻译英语单词的语言将由学生决定。字典程序将有能力将至少15个英语单词翻译成外语 现在我很难让字典程序调用翻译程序。 我的指导老师
Process proc = Runtime.getRuntime().exec("java -jar Translate.jar");
InputStream in = proc.getInputStream();
InputStream err= proc.getErrorStream();
目前的问题是,我的程序似乎无法访问jar文件。
我正在使用Eclipse和Windows7
我创建Translate jar文件的步骤是
在“翻译”项目上单击鼠标右键
出口
选定的可运行Jar文件
选择Dictionary-Dictionary作为启动配置
输入Dictionary\Translate.jar作为导出目标
单击finish,然后继续尝试使用Process runtime
现在我只有两个程序的伪代码,但我专注于找出如何调用translate程序
Dictionary.java
Translate.java
如果我不被允许接受如此多的帮助,有人能告诉我还有哪些网站允许我发布此请求吗?我的导师告诉我们使用该语句是本练习的重点,以了解如何使用进程或如何将基于Java的类连接到另一个jar中的另一个Java类?后者更有用、更简单。我相信是后者,因为他说他只建议使用过程。然而,这似乎是我认为最有效的一个,因为我的其他同学都在使用它。然后我又问了一遍,我不知道还有什么更好的。但是,项目的主要目的是以jar文件的形式调用另一个基于java的类
public class Dictionary {
public static void main(String [] args){
/******************
* Dictionary Program
* Will translate and return a foreign word back
* to the Translate program that this Program is calling.
* It will look up the English word. The Dictionary will use
* Elvish as the foreign language that is being translated.
* Should be able to translate 15 english words.
*/
/**********************************************************
/* External Module code calls Translate and gets output
*from module
/*********************************************************/
/* try
{
// Run a java app in a separate system process
Process proc = Runtime.getRuntime().exec("java -jar Translate.jar");
// Then retreive the process output
InputStream in = proc.getInputStream();
InputStream err= proc.getErrorStream();
BufferedReader reader = new BufferedReader(new InputStreamReader(proc.getInputStream()));
String EngWord = reader.readLine(); //EngWord is the variable sent from the Translate program
while ( (EngWord = reader.readLine()) != null)
do //Pseudo-code of (If, Else Statements provided below)
/**********************************************************************
* Pseudo-code
**********************************************************************/
String EngWord = "Should be a variable that the Translate Program is passing that is the english word";
String foreignWord = "A variable created by this Diction program that will be sent back to the Translate program";
if (EngWord == "dog") {
foreignWord = "elvish equivalent";
} else if (EngWord == "cat") {
foreignWord = "cat in elvish";
} else if (EngWord == "tree"){
foreignWord = "tree in elven";
} else {
EngWord = "nothing? something that can end the loop well";
// I guess this is where the loop must terminate
}
//Must find a way to return the foreignWord back to Translate
/*
} catch (Throwable e){
e.printStackTrace();
}
*/
}
}
public class Translate {
/**************************
* Translate program will pass the Dictionary program
* an English word. When the Dictionary program translate and returns an Elvish word
* This program will print out the English word and its translation into a file
*
*/
public static void main(String [] args) {
//Must find a way to pass the english word to Dictionary
String EngWord = "This is the variable being sent to the Dictionary program...use as parameter?";
//Must use some type of Writer class in order to write the output of both the EngWord and foreignWord
//into an Output file
String foreignWord = "THis is the variable being sent back from the Dictionary program";
//perhaps use runtime before this so Translate can retreive foreignWord from Dictionary?
//Some type of algorithm that will write both the foreignWord and Engword onto an output file.
//Prints (Writes) out to "output.txt"
}
}