java相当于uix cut [英] java equivelant to uix cut
本文介绍了java相当于uix cut的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
我不是 Java 编码员,但需要一个可以执行此操作的命令
i'm not a java coder but need a commnad that will do
cut -d "/" -f1,2,3 MyFile
有什么想法吗?
推荐答案
读取文件.在 /
上拆分每一行,然后打印出前三部分.
Read the file. Split each line on /
and then print out the first three parts.
BufferedReader in = null;
try{
in = new BufferedReader(new FileReader("MyFile"));
String line = "" ;
while((line = in.readLine()) != null){
String[] fields = line.split("/");
System.out.printf("%s/%s/%s\n", fields[0], fields[1], fields[2]) ;
}
}
catch(Exception e){
e.printStackTrace();
}
finally{
if (in != null) {
try {
in.close();
} catch (IOException e) {
}
}
}
这篇关于java相当于uix cut的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文