Solved

Java File renameTo()

Posted on 2004-08-13
16
489 Views
Last Modified: 2010-05-18
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
Comment
Question by:mooy
  • 6
  • 3
  • 2
  • +4
16 Comments
 
LVL 86

Expert Comment

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

In what program are you viewing this?
0
 
LVL 92

Expert Comment

by:objects
ID: 11791403
renameTo() wouldn't change the content of the file.

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

renameTo()  :)
0
 
LVL 6

Expert Comment

by:expertmb
ID: 11791436
renameTo()
it renames the file properly.
0
Networking for the Cloud Era

Join Microsoft and Riverbed for a discussion and demonstration of enhancements to SteelConnect:
-One-click orchestration and cloud connectivity in Azure environments
-Tight integration of SD-WAN and WAN optimization capabilities
-Scalability and resiliency equal to a data center

 
LVL 86

Accepted Solution

by:
CEHJ earned 125 total points
ID: 11791609
>>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
 

Author Comment

by:mooy
ID: 11791620
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
 
LVL 86

Expert Comment

by:CEHJ
ID: 11791637
>>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
 
LVL 92

Expert Comment

by:objects
ID: 11791651
> if i were to parse the txt file, will the square bracket affect it?

most probably not :)
0
 
LVL 13

Expert Comment

by:Webstorm
ID: 11792161
>> 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
 
LVL 3

Expert Comment

by:alskdj80
ID: 11792972
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
 
LVL 86

Expert Comment

by:CEHJ
ID: 11793195
(which i've already said)
0
 
LVL 3

Expert Comment

by:alskdj80
ID: 11793613
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
 
LVL 86

Expert Comment

by:CEHJ
ID: 11793684
ok ;-)
0
 
LVL 3

Expert Comment

by:kumvjuec
ID: 11796706
in wordpad, the file would display correctly
0
 

Author Comment

by:mooy
ID: 11798774
oh thnx...is the notepad problem...zzz

thnx every one
0
 
LVL 92

Expert Comment

by:objects
ID: 11798783
its got nothing to do with renameTo() either :)
0
 
LVL 86

Expert Comment

by:CEHJ
ID: 11799772
8-)
0

Featured Post

Free Tool: Site Down Detector

Helpful to verify reports of your own downtime, or to double check a downed website you are trying to access.

One of a set of tools we are providing to everyone as a way of saying thank you for being a part of the community.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Suggested Solutions

Title # Comments Views Activity
simple java question 3 59
type mismatch (Object[] to double[] 4 33
by zero exception 10 52
jboss wildfly 10.1 10 235
For customizing the look of your lightweight component and making it look lucid like it was made of glass. Or: how to make your component more Apple-ish ;) This tip assumes your component to be of rectangular shape and completely opaque. (COD…
Java functions are among the best things for programmers to work with as Java sites can be very easy to read and prepare. Java especially simplifies many processes in the coding industry as it helps integrate many forms of technology and different d…
This theoretical tutorial explains exceptions, reasons for exceptions, different categories of exception and exception hierarchy.
This video teaches viewers about errors in exception handling.

829 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question