我正在用Java和gradle编写一个控制台应用程序.我正在使用该application插件并正确配置了必填字段build.gradle.
在我的主要课程中,我已经BufferedReader与之相关联System.in.这是问题所在:当我gradle run在项目目录中运行时,阅读器不会等待我的控制台输入.BufferedReader#readLine而是null在第一次通话时返回.对于我正在做的事情,这种行为是不可取的.
解决办法是什么?是否有一个单独的控制台应用程序插件用于gradle或我是否需要以application某种方式调整插件以满足我的需求?
当我通过扫描仪读取文件时,我的程序中出现了运行时异常.
java.util.NoSuchElementException: No line found
at java.util.Scanner.nextLine(Unknown Source)
at Day1.ReadFile.read(ReadFile.java:49)
at Day1.ParseTree.main(ParseTree.java:17)
Run Code Online (Sandbox Code Playgroud)
我的代码是:
while((str=sc.nextLine())!=null){
i=0;
if(str.equals("Locations"))
{
size=4;
t=3;
str=sc.nextLine();
str=sc.nextLine();
}
if(str.equals("Professions"))
{
size=3;
t=2;
str=sc.nextLine();
str=sc.nextLine();
}
if(str.equals("Individuals"))
{
size=4;
t=4;
str=sc.nextLine();
str=sc.nextLine();
}
int j=0;
String loc[]=new String[size];
while(j<size){
beg=0;
end=str.indexOf(',');
if(end!=-1){
tmp=str.substring(beg, end);
beg=end+2;
}
if(end==-1)
{
tmp=str.substring(beg);
}
if(beg<str.length())
str=str.substring(beg);
loc[i]=tmp;
i++;
if(i==size ){
if(t==3)
{
location.add(loc);
}
if(t==2)
{
profession.add(loc);
}
if(t==4)
{
individual.add(loc);
}
i=0;
}
j++;
System.out.print("\n");
}
Run Code Online (Sandbox Code Playgroud)