我想转到命令行并输入输入,因此BufferReader可以访问该文件。我该怎么做?
输入将是" java TagMatching path_to_html_file.html"
// Importing only the classes we need
import java.io.BufferedReader;
import java.io.FileReader;
import java.io.IOException;
public class TagMatching {
public static void main(String[] args) {
BufferedReader br = null;
// try to read the file
try {
br = new BufferedReader(new FileReader(**/*DONT KNOW WHAT TO DO*/**));
String line;
} catch (IOException e) {
e.printStackTrace();
}
}
}
答案 0 :(得分:4)
输入将为
java TagMatching path_to_html_file.html
在应用程序名称(TagMatching
)之后,您找到了参数(path_to_html_file.html
),这是主方法的String[] args
,所以只需使用它们,在这种情况下args[0]
public static void main(String[] args) {
BufferedReader br = null;
// try to read the file
try {
// check if there are some arguments
if (null != args[0] &&
// lenght > 5 because a.html will be shortest filename
args[0].lenght > 5 &&
// check if arguments have the correct file extension
args[0].endsWith(".html"))
{
br = new BufferedReader(new FileReader(args[0]));
// do more stuff
}
} catch (IOException e) {
e.printStackTrace();
}
}
1}}:
$('#lehrberuf ').on('change',function(){
var index = $('#lehrberuf option').index($(this).find(':selected'));
console.log(index);
$('.hiddenmessage'+(index+1)).toggle();
});
答案 1 :(得分:0)
要从控制台获取输入,您必须使用像这样的扫描仪;
Scanner in = new Scanner(System.in);
System.out.println("Enter file path");
String s = in.nextLine(); //C:\\testing.txt
在FIleReader中使用该文件路径就像这样使用;
br = new BufferedReader(new FileReader(s));
答案 2 :(得分:0)
与args [0]完全一样。
因此,br = new BufferedReader(new FileReader(args[0]));
将按照发问者的意图