题目要求是
java -jar word-counts.jar <-a|-c> <input_filename> <output_filename>
input_filename -- is a relative or absolute path to the input file to process,
or '-' to indicate input should be read from stdin
output_filename -- relative or absolute path to the output file to write the results to,
or '-' to indicate input should written to stdout
-a -- output words and counts ordered alphabetically by the words
-c -- output words and counts ordered by count descending在函数中怎么检测“-”号是否存在,“-”号如果存在的话怎么检测后面参数是a还是c
java -jar word-counts.jar <-a|-c> <input_filename> <output_filename>
input_filename -- is a relative or absolute path to the input file to process,
or '-' to indicate input should be read from stdin
output_filename -- relative or absolute path to the output file to write the results to,
or '-' to indicate input should written to stdout
-a -- output words and counts ordered alphabetically by the words
-c -- output words and counts ordered by count descending在函数中怎么检测“-”号是否存在,“-”号如果存在的话怎么检测后面参数是a还是c
解决方案 »
- 有哪位高手知到微信是用什么语言写的不?
- 为什么SWT里Radio样式的MenuItem在被取消选中时也会产生Selection事件
- java中的bo(business object)怎么理解?怎么运用?举个最简单的例子说明一下?
- 扫描网段上的web server的类型,Timeout,retry应该怎么用?用的是HttpURLConnection类
- 一个java问题;统计abc在文件1.txt中出现的次数
- 工作太难找?
- 怎么回复帖子?
- 请问在swing布局中,如何使CardLayout 布局的lpanel切换卡片.
- 请问考试的顺序问题?
- 谁用过ssl,给点思路吧
- 在linux上,为什么不用配置环境变量还能运行java程序呢?
- NetBeans明显比Eclipse好用
String tt = "java -jar word-counts.jar -a <input_filename> <output_filename>";
if (tt.contains("-a")) {
System.err.println("aaaaa");
} else if(tt.contains("-c")){
System.err.println("ccccccccccc");
}
}
run:
aaaaa
成功生成(总时间:0 秒)
public class WordCount {
public static void main(String[] args) {
InputStream is = null;
OutputStream os = null;
boolean alphaOrder = true; if (args.length == 2 || args.length == 3) {
int i = 0; if (args.length == 3) {
if (args[0] == null) {
// 输出错误信息
return;
} switch (args[i++]) {
case "-a":
break;
case "-c":
alphaOrder = false;
break;
default:
// 输出错误信息
return;
}
} if ("-".equals(args[i]))
is = System.in;
else
try {
is = new FileInputStream(args[i]);
} catch (IOException ex) {
ex.printStackTrace();
return;
} i++; if ("-".equals(args[i]))
os = System.out;
else
try {
os = new FileOutputStream(args[i]);
} catch (IOException ex) {
ex.printStackTrace();
return;
}
} else {
// 输出错误信息
return;
} // 数据读写和单词计数部分自己可以写了吧
}
}