使用将被调回程序的字典程序调用翻译程序

时间:2013-09-20 03:20:24

标签: java process jar inputstream runtime.exec

我是编码中的一个完整的菜鸟,我想知道我是否能得到一些帮助

我有这个项目,基本上我需要做的是:

  

创建2个可执行程序。翻译计划和字典计划。这些程序可以用任何语言编写。

     

翻译程序会将字典程序传递给英语单词。 Dictionary程序将翻译并返回一个外来单词。翻译程序将打印出英文单词并将其翻译成文件。

     

字典程序将查找英文单词并以外语返回其翻译。词典程序将能够将选定数量的英语单词翻译成另一种语言。词典程序将英语单词翻译成语言将由学生决定。词典程序将能够将至少15个英语单词翻译成外语。 “

现在我无法让Dictionary程序调用Translate程序。 我的导师告诉我们使用声明

Process proc = Runtime.getRuntime().exec("java -jar Translate.jar"); 

InputStream in = proc.getInputStream();
InputStream err= proc.getErrorStream();

目前问题是我的程序似乎无法访问jar文件。 我正在使用Eclipse和Windows 7 我创建Translate jar文件的步骤是

  1. 右键单击“翻译项目”
  2. 出口
  3. 选定的Runnable Jar文件
  4. 选择字典 - 字典作为启动配置
  5. 键入Dictionary \ Translate.jar作为导出目的地
  6. 单击完成,然后继续尝试使用Process runtime
  7. 现在我只有两个程序的伪代码,但我专注于搞清楚如何调用翻译程序。

    Dictionary.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();
           } 
            */
        }   
    }
    

    Translate.java

    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"
        }
    
    }
    

    如果我不被允许接受这么多的帮助,有人可能会告诉我其他网站可能会被允许发布此请求吗?

0 个答案:

没有答案
相关问题