Warning: file_get_contents(/data/phpspider/zhask/data//catemap/9/loops/2.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
如何在java中读取文件以进行处理_Java_Loops_File_Switch Statement - Fatal编程技术网

如何在java中读取文件以进行处理

如何在java中读取文件以进行处理,java,loops,file,switch-statement,Java,Loops,File,Switch Statement,我试图提供一个简单的命令行用户界面,允许应用程序的用户指定文件(纯文本或密文)、操作(编码或解码)和任何其他参数。这是我到目前为止,我主要需要帮助,使菜单,因为我不断得到一个错误,我无法摆脱 另外,我想问一下我是如何使一个lookuptable来编码我通过的文件的 您在java中命名方法及其参数的做法很糟糕,它们必须以小写字母开头。此外,您有两个具有相同名称和签名的主要方法。因此,代码甚至不会编译。类名称必须以大写字母开头 import java.util.Scanner; impor

我试图提供一个简单的命令行用户界面,允许应用程序的用户指定文件(纯文本或密文)、操作(编码或解码)和任何其他参数。这是我到目前为止,我主要需要帮助,使菜单,因为我不断得到一个错误,我无法摆脱

另外,我想问一下我是如何使一个lookuptable来编码我通过的文件的


您在java中命名方法及其参数的做法很糟糕,它们必须以小写字母开头。此外,您有两个具有相同名称和签名的主要方法。因此,代码甚至不会编译。类名称必须以大写字母开头
 import java.util.Scanner;
    import java.util.*;
    import java.io.File;
    
    
    public class test {
    
    //Function display(String G) takes as input the string and displays the attributes
    public static void display(String G){
    
    
        //split() allows splitting of a string based "!" and returns an array of strings
    
    
    
    }
    
    public void Runner(){
        Scanner sc= new Scanner(System.in);
    
        int choice;
    
            System.out.println("***************************************************");
            System.out.println("* GMIT - Dept. Computer Science & Applied Physics *");
            System.out.println("*                                                 *");
            System.out.println("*              Zimmerman Encoder 1.0              *");
            System.out.println("*          (Linguistic Encoding System)           *");
            System.out.println("*                                                 *");
            System.out.println("***************************************************");
    
        System.out.println("1) Enter File Name to Process");//Ask user to specify the file to process. Do NOT hardcode paths or file names
        System.out.println("2) Generate Lookup Tables"); //Read in common words as File f = new File("./commonEnglishWords.txt");
        System.out.println("3) Encode Mode"); //Ask user for output file or just use out.txt
        System.out.println("4) Decode Mode"); //Ask user for output file or just use out.txt
        System.out.println("5) Quit"); //Terminate
        System.out.println("\nSelect Option [1-5]>");
    
        choice=sc.nextInt();
        sc.nextLine();
    
        return choice;
    
    
    }
    
    public static void main(String[] args) {
        // TODO Auto-generated method stub
    
    
        Scanner sc= new Scanner(System.in);
    
        int choice;
    
    
        while(true){
            choice= menu();
                  switch(choice)
                  {
                  case 1 : {
    
                      System.out.println("Enter file to process");
                      Scanner fileNameScanner = new Scanner( System.in );
                      String fileName = "";
                      if ( fileNameScanner .hasNext() ) {
                      fileName = fileNameScanner.next();
                        }
    
                      break;
                   }
    
                  case 2: {
                  System.out.println("Generate lookup table");
                  break;
                  }
    
                  case 3: {
                  System.out.println("Generate lookup table");
                  break;
                  }
    
                  case 4: {
                  System.out.println("Generate lookup table");
                  break;
                      }
    
                  case 5: {
                      System.exit(0);
                  }
    
                  default: {
                      break;
                  }
                  }
        }
    
     }
    
    
    public static void main(String[] args) {
    
            new Runner().go();
    
    
    
    
    
    }