[英]Where to insert file path in this Java Program?
我是Java的新手,目前正在使用Java分析文件比較工具,該工具可比較此鏈接中的兩個文件:
http://www.java2s.com/Code/Java/File-Input-Output/Difftextfiledifferenceutility.htm
但沒有在文件中的任何位置提及文件路徑。 我應該在哪里插入文件路徑? 我搜索了google,並檢查了Java Filestram和緩沖區輸入輸出流。 但是沒有發現任何有用的信息。
我也搜索了stackoverflow,但似乎不存在這樣的問題。
通常,文件路徑應該在主文件中更新,對嗎?
但是似乎在主文件中丟失了。
public static void main(String argstrings[])
{
if ( argstrings.length != 2 ) {
System.err.println("Usage: diff oldfile newfile" );
System.exit(1);
}
Diff d = new Diff();
d.doDiff(argstrings[0], argstrings[1]);
return;
}
您的程序將文件名作為參數。 因此,在提供命令行輸入的同時,您可以提供完整的文件路徑。 像這樣:
java yourClassName volume1:\dir1\filename1 volume2:\dir2\filename2
您當然可以按照juned告訴您的方式進行操作,但是如果您希望程序更加用戶友好,請嘗試像這樣操作主要方法
public static void main(String[] args) throws ParseException {
try{
Scanner in = new Scanner(System.in);
System.out.println("Enter the path of old file");
String oldFile = in.nextLine();
System.out.println("Enter the path of new file");
String newFile = in.nextLine();
Diff d = new Diff();
if(!oldFile.equals("") && !newFile.equals("")) {
d.doDiff(oldFile, newFile);
}
}
catch (Exception e){
e.printStackTrace();
}
}
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.