Home arrow static arrow Java Programming [Archive] - Changing a file sufix
Warning: Creating default object from empty value in /www/htdocs/w008deb8/wiki/components/com_staticxt/staticxt.php on line 51
Java Programming [Archive] - Changing a file sufix
This topic has 2 replies on 1 page.

Posts:2
Registered: 7/21/04
Changing a file sufix   
Jul 21, 2004 1:17 AM



 
Hi

I'm trying to change the suffix of an existing file from '.jr1' to '.txt' and renameTo() returns false because the File jr in the following code has not been created. I think, because it exists, albeit with a different suffix.
Here is the code :

public void RenameJROneFile() {
try {
location = location.replace( '/', '
' );
System.out.println(jrOneFile.getAbsolutePath());
int end = imageName.lastIndexOf(".");
imageName = imageName.substring(0, end);
imageName = imageName.concat(".txt");
File jr = new File(location + "
" + imageName);
System.out.println( jrOneFile.getPath() + " rename to " + jr.getPath() );
boolean bool = jrOneFile.renameTo(jr);
System.out.println( bool );
}catch ( Exception e ) { e.printStackTrace();}
}

Any ideas ?

Steve

 

Posts:6,147
Registered: 11/9/00
Re: Changing a file sufix   
Jul 21, 2004 2:21 AM (reply 1 of 2)



 
Java doesn't recognise any special meaning in extenstions, so there's no problem having two files differing only in extension.

It's more likely to be permissions problems or incorrect filenames. Check jrOneFile.exists(). And it's not good practice to use all these backslashes. Use new File(directory, name) for a start and File.separatorChar if you must.
 

Posts:2
Registered: 7/21/04
Re: Changing a file sufix   
Jul 21, 2004 2:45 AM (reply 2 of 2)



 
Thanks.
The problem was elsewhere.
 
This topic has 2 replies on 1 page.