Java - Write code to Place a prefix on the filename.

Requirements

Write code to Place a prefix on the filename.

Demo

//package com.book2s;

public class Main {
    public static void main(String[] argv) {
        String path = "book2s.com";
        String prefix = "book2s.com";
        System.out.println(prefixFilename(path, prefix));
    }//from  w w w.  j  a v a2s . c  o m

    /**
     * Places a prefix on the filename.
     * <br><br>
     * Note: Only works for windows style paths. 
     */
    public static String prefixFilename(String path, String prefix) {
        int index = path.lastIndexOf("\\");
        return (path.substring(0, index) + "\\" + prefix + path
                .substring(index + 1));
    }
}

Related Exercise