[问题] 新手关于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