[問題] 新手關於I/O問題

作者: QQron (Run)   2015-05-25 04:12:20
各位高手不好意思,小弟是剛學java差不多十天的超新手
關於io的部分有點問題,我是看書自學,一題範例是教如何用io拷貝使用者指定檔案
而我在終端機方面有些疑惑
小弟用的是在mac air上用eclipse
只是在eclipse上面模擬都沒什麼問題,可有些需要用到指令列引數的,我實在不知道mac os上,
終端機路徑要怎麼使用與設定。
我用的書是java程式設計導論(Y.Daniel Liang),他主要範例都用windows寫,一般沒什麼問題,但在終端機的部分我就混亂了,不知道怎麼做
class存放位置
Macintosh HD\使用者\Rum\workspace\Practice\test\Copy.java
程式碼
package test;
import java.io.*;
public class Copy {
public static void main(String[] args) throws IOException{
if (args.length != 2){
System.out.println("Usage: java Copy sourceFile targetfile");
System.exit(1);
}
File sourceFile = new File(args[0]);
if(!sourceFile.exists()){
System.out.println("Source file " + args[0] + " does not exist");
System.exit(2);
}
File targetFile = new File(args[1]);
if(targetFile.exists()){
System.out.println("Target file " + args[1]
+ " already exists");
System.exit(3);
}
try (
BufferedInputStream input =
new BufferedInputStream(new FileInputStream(sourceFile));
BufferedOutputStream output =
new BufferedOutputStream(new FileOutputStream(sourceFile));
){
int r, numberOfBytesCopied = 0;
while((r = input.read()) != -1){
output.write((byte)r);
numberOfBytesCopied++;
}
System.out.println(numberOfBytesCopied + " bytes copied");
}
}
}
希望有大大能幫我解惑,這種有用到指令列的我都不知道該怎麼測試
這題是java程式設計導論(第十版)
p.709頁的範例

Links booklink

Contact Us: admin [ a t ] ucptt.com