• Status: Solved
  • Priority: Medium
  • Security: Public
  • Views: 523
  • Last Modified:

Java File renameTo()

hi ppl,


i stumble upon a problem...im not sure whether it got to do with the encoding..

i have this XML file in "UTF-8" encoding (invoice.xml)

i wan to write a program to change this filename to (invoice.txt) , i am using renameTo() function but the output i see from the txt file have a special character contain in it...

the new line(\n) from the XML file is changed to something like a square bracket ( [] )..

is there any method to simply change the extension of the file?

thnx, this is rather urgent...depends on all of u now
0
mooy
Asked:
mooy
  • 6
  • 3
  • 2
  • +4
1 Solution
 
CEHJCommented:
>>the new line(\n) from the XML file is changed to something like a square bracket ( [] )..

In what program are you viewing this?
0
 
objectsCommented:
renameTo() wouldn't change the content of the file.

> is there any method to simply change the extension of the file?

renameTo()  :)
0
 
expertmbCommented:
renameTo()
it renames the file properly.
0
Concerto Cloud for Software Providers & ISVs

Can Concerto Cloud Services help you focus on evolving your application offerings, while delivering the best cloud experience to your customers? From DevOps to revenue models and customer support, the answer is yes!

Learn how Concerto can help you.

 
CEHJCommented:
>>the new line(\n) from the XML file is changed to something like a square bracket ( [] )..

What you're probably doing here is viewing the file in a rudimentary Windows editor. The 'square' is its way of saying "help - i've got non-Windows line breaks and i can't cope!"

This can be safely ignored. If you however use Readers/Writers to manipulate your xml file, you should find that line breaks are rendered correctly for the platform you happen to be on.
0
 
mooyAuthor Commented:
oh i see...

therefore is only when i use Notepad to view the txt file, i get those square thingy...

if i were to parse the txt file, will the square bracket affect it?
0
 
CEHJCommented:
>>if i were to parse the txt file, will the square bracket affect it?

No, not unless by 'parsing' you mean some sort of binary manipulation, which i guess you don't ....
0
 
objectsCommented:
> if i were to parse the txt file, will the square bracket affect it?

most probably not :)
0
 
WebstormCommented:
>> therefore is only when i use Notepad to view the txt file, i get those square thingy...
You should also see this square character when you view the xml file with Notepad
0
 
alskdj80Commented:
you see a square character in notepad because windows doesnt know how to handle \n... windows requires \r\n to display a newline, thats the reason for the square character
0
 
CEHJCommented:
(which i've already said)
0
 
alskdj80Commented:
CEHJ, relax, im not looking for expert points... its just that no one mentioned \r\n specifically, so i thought i should add it
0
 
CEHJCommented:
ok ;-)
0
 
kumvjuecCommented:
in wordpad, the file would display correctly
0
 
mooyAuthor Commented:
oh thnx...is the notepad problem...zzz

thnx every one
0
 
objectsCommented:
its got nothing to do with renameTo() either :)
0
 
CEHJCommented:
8-)
0

Featured Post

Industry Leaders: We Want Your Opinion!

We value your feedback.

Take our survey and automatically be enter to win anyone of the following:
Yeti Cooler, Amazon eGift Card, and Movie eGift Card!

  • 6
  • 3
  • 2
  • +4
Tackle projects and never again get stuck behind a technical roadblock.
Join Now