Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • Home
  • SEARCH
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 4605466
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 22, 20262026-05-22T00:26:09+00:00 2026-05-22T00:26:09+00:00

I experienced a strange behavior from Java File file = new File(test.txt); file.reName(new File(test1.txt));

  • 0

I experienced a strange behavior from Java

File file = new File("test.txt");
file.reName(new File("test1.txt"));

The file successfully rename from test.txt to test1.txt, but if I do

System.out.println(file.getCanonicalPath()); //This return test.txt

Is this expected? And what is a clean way to solve this?

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-05-22T00:26:09+00:00Added an answer on May 22, 2026 at 12:26 am

    Yes, this is expected. File objects are immutable, and simply represent a filename.

    You can think of it like this: a File object is a reference to a file, not the file itself.

    This behaviour can actually be useful – for example, imagine that you are moving a previous version of a file out of the way to avoid overwriting it (i.e. to create a backup copy). If you rename foo1.txt to foo1.bak, then the original File variable that contained foo1.txt will still contain it, and can be used to open a FileOutputStream.

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I've experienced rather strange behavior of JSTL forEach tag. I have some bean called
Im very new to C programing, but have limited experience with Python, Java, and
I'm an experienced client application developer (C++/C#), but need to come up to speed
I'm a pretty experienced Java programmer that's been doing quite a bit of Win32
Our team is experienced in web development (tomcat/Oracle) but not with AJAX on our
I'm a pretty experienced Grails developer, but most of my experience has been with
I am a somewhat experienced Rails developer and I thought I would try out
Since upgrading to Xcode 3.2.1, I've experienced a strange issue that has really killed
I am experiencing a strange behavior with very basic web service development. This question
I have experienced a strange problem in windows vista and above. When I use

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.