tags:

views:

49

answers:

3

i'm not a java coder but need a commnad that will do

cut -d "/" -f1,2,3 MyFile 

Any ideas?

A: 

you can read the content of file in String then use subString method.

Here is documentations

org.life.java
+1  A: 

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) {
        }
    }
}
dogbane
IMHO, it would be better if you had describe the difference between a declarative language a non declarative as Java instead of showing that You are able to write a piece of code. The question was about the command not the solution.
Vash
A: 

The main difference between Java coding and that script example is that they use different programming paradigm lest say that Java use Object Programing and that example can be assigned to declarative programing (You only express the logic, not the way to get the result) so no commands in Java.

So there is no command that You can use for this type of functionality.

There might be some package with this type of static procedure that works like that cut program. But still You will have to write a program to use it.

So if You would describe us the purpose of usage of this program (cut) )we could be able to provide You a good answer.

Vash
@Vash - you should know by now that there are no god answers on SO. Even @Jon Skeet is only god- *like*.
Stephen C