0
package javaapplication6;
import java.util.*;

public class JavaApplication6{

public static void main(String[] args){

    Scanner vh=new Scanner(System.in);

    String niz="";

    char pod_niz=vh.next().charAt(0);
    char pod_niz2=vh.next().charAt(0);

        int index=niz.indexOf(pod_niz);

                String m=niz.replace(niz.charAt(index),pod_niz2);


            System.out.println(m);
}
}

So this program changes one letter from a string.So for example:

String niz="monkey";
char pod_niz='y';
char pod_niz='x';

I get monkex

Now i have a file (D:\file.bin) and i want to change it to File.bin using this program. How to do that? Maybe I need to store the file name into a String, change it, then change the file name using the data which the String contains.

Thanks..

kostad
  • 3
  • 4
  • I guess this has the answer you are looking for: [link]http://stackoverflow.com/questions/1158777/renaming-a-file-using-java – WrongASP Feb 06 '14 at 19:28
  • Maybe you're right. Have you tried it that way? – keshlam Feb 06 '14 at 19:47
  • i think this can't help me.. – kostad Feb 06 '14 at 19:59
  • How do you intend to use this program? Do you expect the user to enter the name of the file or is it hard-coded? Should it apply the rename in all the files in a folder? On that depends what solution you need. – Daniel Feb 06 '14 at 20:20
  • actually i need a program that will read all the files in a directory,enter 2 letters and if some file contains the first letter it must change it to the second one( like the example i gave ).But for now i need just for one file. – kostad Feb 06 '14 at 20:40

0 Answers0