lundi 29 juin 2015

java8 class for composing file paths

I'm currently reworking some code of mine. This code looks currently something like this:

File makeFile() {

    StringBuilder builder = new StringBuilder();

    builder.append( "/" );

    if( a ) builder.append( foodir ).append( '/' );
    if( b ) builder.append( bardir ).append( '/' );

    builder.append( "file.txt" );

    return new File( b.toString() );

I really don't like this code very much because it uses StringBuilder to build something which should really be some kind of Path object in the first place.

So is there -- at least in Java8 -- some means of building Path or File objects in a more clean way?

(Note: I'm not looking for using Collections and later joining them. I'm looking for something working directly with filesystem objects.)

Aucun commentaire:

Enregistrer un commentaire