What the best way is change file extention of Java?
+2
A:
Just rename it using File.renameTo(String name):
public static void main(String[] argv) throws IOException {
// Construct the file object from existing file.
File f = new File("myfile.toto");
// Rename it
f.renameTo(new File("myfile.myext"));
}
Manuel Selva
2010-10-19 08:31:58
are you shure?? not work !
Chen Xinhua
2010-10-19 08:38:37
My answer works for Java where your question was originally postedand not Javascript
Manuel Selva
2010-10-19 08:40:04
<script type="text/java">public static void main(String[] argv) throws IOException {// Construct the file object from existing file.File f = new File("myfile.toto"); // Rename itf.renameTo(new File("myfile.myext"));}</script> do not work !!
Chen Xinhua
2010-10-19 08:47:26
when get 125 vote down you Answer
Chen Xinhua
2010-10-19 08:49:02
my example is a full Java application with a main method. Just use: File f = new File("myfile.toto"); f.renameTo(new File("myfile.myext"));
Manuel Selva
2010-10-19 08:54:29
did not know to use it. bad implementation
Chen Xinhua
2010-10-19 09:00:34
I you answer Admin no work
Chen Xinhua
2010-10-19 10:08:06
+1
A:
First You should get familiar with What file extension is.
Next correct Your question, do You want only change it or how to change it.
If You only want to change it, the we can assume that the extension i really there.
But for answer how to change extension. The answer should provide information about finding one, parsing properly the string etc...
And you should also define what the best mean for You.
For me best solution would be.
1 - Retrieve the characters after after last index of '.'.
2 - Verify that string if any in defined extensions by system.
3 - If found remove it,
4 - Add to file name new extension.
Vash
2010-10-19 08:54:25