Solved

Java File renameTo()

Posted on 2004-08-13
16
464 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
 
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
Highfive Gives IT Their Time Back

Highfive is so simple that setting up every meeting room takes just minutes and every employee will be able to start or join a call from any room with ease. Never be called into a meeting just to get it started again. This is how video conferencing should work!

 
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

Do You Know the 4 Main Threat Actor Types?

Do you know the main threat actor types? Most attackers fall into one of four categories, each with their own favored tactics, techniques, and procedures.

Join & Write a Comment

Introduction This article is the first of three articles that explain why and how the Experts Exchange QA Team does test automation for our web site. This article explains our test automation goals. Then rationale is given for the tools we use to a…
In this post we will learn how to connect and configure Android Device (Smartphone etc.) with Android Studio. After that we will run a simple Hello World Program.
This theoretical tutorial explains exceptions, reasons for exceptions, different categories of exception and exception hierarchy.
This tutorial will introduce the viewer to VisualVM for the Java platform application. This video explains an example program and covers the Overview, Monitor, and Heap Dump tabs.

746 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

Need Help in Real-Time?

Connect with top rated Experts

10 Experts available now in Live!

Get 1:1 Help Now