?
Solved

Java File renameTo()

Posted on 2004-08-13
16
Medium Priority
?
506 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
VIDEO: THE CONCERTO CLOUD FOR HEALTHCARE

Modern healthcare requires a modern cloud. View this brief video to understand how the Concerto Cloud for Healthcare can help your organization.

 
LVL 86

Accepted Solution

by:
CEHJ earned 500 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: Subnet Calculator

The subnet calculator helps you design networks by taking an IP address and network mask and returning information such as network, broadcast address, and host range.

One of a set of tools we're offering 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

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…
Basic understanding on "OO- Object Orientation" is needed for designing a logical solution to solve a problem. Basic OOAD is a prerequisite for a coder to ensure that they follow the basic design of OO. This would help developers to understand the b…
Viewers learn how to read error messages and identify possible mistakes that could cause hours of frustration. Coding is as much about debugging your code as it is about writing it. Define Error Message: Line Numbers: Type of Error: Break Down…
Viewers will learn about the regular for loop in Java and how to use it. Definition: Break the for loop down into 3 parts: Syntax when using for loops: Example using a for loop:
Suggested Courses
Course of the Month14 days, 9 hours left to enroll

771 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