开发者

Change file extension?

What the best way is change file ex开发者_如何学Ctension of Java?


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"));

}


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.


Using Powershell:

cat abc.data | %{$_ -replace " ",","} | sc abc.csv  

Using Unix Sed command:

sed 's/ /,/g' abc.data > abc.csv
0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜