作者QQron (Run)
看板java
标题[问题] 新手关於I/O问题
时间Mon May 25 04:12:20 2015
各位高手不好意思,小弟是刚学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页的范例
--
※ 发信站: 批踢踢实业坊(ptt.cc), 来自: 223.136.7.183
※ 文章网址: https://webptt.com/cn.aspx?n=bbs/java/M.1432498342.A.03E.html