gpt4 book ai didi

java - 如何使用扫描仪从命令行读取文件

转载 作者:行者123 更新时间:2023-11-30 02:35:15 26 4
gpt4 key购买 nike

不会提示用户输入文件?请帮助我

public static void main (String args []){
if (0 < args.length) {
File inFile = new File(args[0]); // Make sure the file exists, can read, etc...
while (!inFile.exists()) {
Scanner console = new Scanner (inFile);
System.out.println ("Input file:"); //prompt user to input file
String inFileName = console.nextLine();
System.out.println ("Input file:"); //prompt user to input file
inFileName =inFileName.trim(); //get rid of whitespace
System.out.println(inFileName);
inFile = new File (inFileName);
}

最佳答案

旧方法:

BufferedReader reader = new BufferedReader( new InputStreamReader( System.in)); String userInput = reader.readLine();

新方法:

Console console = System.console(); 
if( console != null) { String userInput = console.readLine();

关于java - 如何使用扫描仪从命令行读取文件,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/43267616/

26 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com