Solved

Java File renameTo()

Posted on 2004-08-13
16
499 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
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
  • 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
Technology Partners: 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!

 
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

Instantly Create Instructional Tutorials

Contextual Guidance at the moment of need helps your employees adopt to new software or processes instantly. Boost knowledge retention and employee engagement step-by-step with one easy solution.

Question has a verified solution.

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

For beginner Java programmers or at least those new to the Eclipse IDE, the following tutorial will show some (four) ways in which you can import your Java projects to your Eclipse workbench. Introduction While learning Java can be done with…
Introduction This article is the second of three articles that explain why and how the Experts Exchange QA Team does test automation for our web site. This article covers the basic installation and configuration of the test automation tools used by…
This tutorial covers a step-by-step guide to install VisualVM launcher in eclipse.
This video teaches viewers about errors in exception handling.
Suggested Courses

739 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