Solved

Java File renameTo()

Posted on 2004-08-13
16
483 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
Efficient way to get backups off site to Azure

This user guide provides instructions on how to deploy and configure both a StoneFly Scale Out NAS Enterprise Cloud Drive virtual machine and Veeam Cloud Connect in the Microsoft Azure Cloud.

 
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

Netscaler Common Configuration How To guides

If you use NetScaler you will want to see these guides. The NetScaler How To Guides show administrators how to get NetScaler up and configured by providing instructions for common scenarios and some not so common ones.

Question has a verified solution.

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

Suggested Solutions

Title # Comments Views Activity
splitOdd10 challenge 5 109
How to convert String matching to regex in java 4 34
Java Restore security prompts not working 10 16
going to wrong jsp page 2 22
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…
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 will learn about if statements in Java and their use The if statement: The condition required to create an if statement: Variations of if statements: An example using if statements:
This tutorial covers a practical example of lazy loading technique and early loading technique in a Singleton Design Pattern.

832 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