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 7011237
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 27, 20262026-05-27T22:06:04+00:00 2026-05-27T22:06:04+00:00

This is a simple class to show 4 cases. Sorry for my english (is

  • 0

This is a simple class to show 4 cases.
Sorry for my english (is bad)

public static void main(String[] args) throws IOException {

    //TODO De temporal a archivo en directorio
    //TODO from file in temporary folder to file in common folder.
    File fromTemp_Dir = File.createTempFile("Temp_Dir_FROM", ".temp");
    File toTemp_Dir = new File ("Temp_Dir");        

    BufferedWriter bufferWriterTemp_DirFROM = new BufferedWriter(new FileWriter(fromTemp_Dir));
    bufferWriterTemp_DirFROM.write("Temp_Dir_FROM");
    bufferWriterTemp_DirFROM.close();

    BufferedWriter bufferWriterTemp_DirTO = new BufferedWriter(new FileWriter(toTemp_Dir));
    bufferWriterTemp_DirTO.write("Temp_Dir_TO");
    bufferWriterTemp_DirTO.close();

    System.out.println("fromTemp_Dir exist? "+fromTemp_Dir.exists());
    System.out.println("toTemp_Dir exist? "+toTemp_Dir.exists());


    toTemp_Dir.delete();
    if (!fromTemp_Dir.renameTo(toTemp_Dir)){
        System.out.println("rename fail 'De temporal a archivo en directorio'");
    }else {
        System.out.println("Rename successful 'De temporal a archivo en directorio'");
    } 


    //TODO De archivo a temporal
    //TODO from file in common folder to file in temporary folder.
    File fromDir_Temp = new File ("Dir_FROM");
    File toDir_Temp = File.createTempFile("Dir_Temp_TO", ".temp");

    BufferedWriter bufferWriterDir_TempFROM = new BufferedWriter(new FileWriter(fromDir_Temp));
    bufferWriterDir_TempFROM.write("Dir_Temp_FROM");
    bufferWriterDir_TempFROM.close();

    BufferedWriter bufferWriterDir_TempTO = new BufferedWriter(new FileWriter(toDir_Temp));
    bufferWriterDir_TempTO.write("Dir_Temp_TO");
    bufferWriterDir_TempTO.close();

    toDir_Temp.delete();
    if (!fromDir_Temp.renameTo(toDir_Temp)){
        System.out.println("rename fail 'De archivo en directorio a temporal'");
    } else{
        System.out.println("rename successful 'De archivo en directorio a temporal'");
    }


    //TODO De temporal a temporal
    //TODO from temporary folder to temporary folder
    File fromTemp = File.createTempFile("archivoTempFROM_", ".temp");
    File toTemp = File.createTempFile("archivoTempTO_", ".temp");

    BufferedWriter bufferWriterFROMTemp = new BufferedWriter(new FileWriter(fromTemp));
    bufferWriterFROMTemp.write("archivoTempFROM");
    bufferWriterFROMTemp.close();

    BufferedWriter bufferWriterTOTemp = new BufferedWriter(new FileWriter(toTemp));
    bufferWriterTOTemp.write("archivoTempTO");
    bufferWriterTOTemp.close();

    toTemp.delete();
    if (!fromTemp.renameTo(toTemp)){
        System.out.println("rename fail 'De temporal a temporal'");
    }else {
        System.out.println("Rename successful 'De temporal a temporal'");
    } 

    //TODO De archivo a archivo en directorio
    //TODO from file in common directory to file in common directory 
    File fromDir = new File("archivoDirFROM");
    File toDir = new File("archivoDirTO");

    BufferedWriter bufferWriterFROMDir = new BufferedWriter(new FileWriter(fromDir));
    bufferWriterFROMDir.write("archivoDirFROM");
    bufferWriterFROMDir.close();

    BufferedWriter bufferWriterTODir = new BufferedWriter(new FileWriter(toDir));
    bufferWriterTODir.write("archivoDirTO");
    bufferWriterTODir.close();

    toDir.delete();
    if (!fromDir.renameTo(toDir)){
        System.out.println("rename fail 'De archivo a archivo en directorio'");
    }else {
        System.out.println("Rename successful 'De archivo a archivo en directorio'");
    } 

}

Show in my console

fromTemp_Dir exist? true
toTemp_Dir exist? true
rename fail ‘De temporal a archivo en directorio’
rename fail ‘De archivo en directorio a temporal’
Rename successful ‘De temporal a temporal’
Rename successful ‘De archivo a archivo en directorio’

This class works on some PCs but not in other PC (tested in 7 PCs, 5 work, 2 not work), all with ubuntu installed.

Supposedly it is a permissions problem but I have set the PC as administrator and root.

I tried with gksu and sudo, but does not work.

Any solution?

Thanks.

  • 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-27T22:06:05+00:00Added an answer on May 27, 2026 at 10:06 pm

    Change the renameTo() method for

    Files.move(new File(newFilePath), new File(oldFilePath));
    

    this is working perfectly.

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

Sidebar

Related Questions

take this simple code: class A{ public: virtual void foo() = 0; void x(){
Consider this simple example - public class Person { private String name; private Date
I define this simple class public class SimpleClass { public string Val1 {get;set;}; public
I have this simple class public class Position{ int x; int y; Position(int x,int
Consider this simple AS3 class. package { import flash.display.Sprite; import flash.display.MovieClip; public class MySprite
Hai. I was making this simple string class and was wondering if there was
I have this very simple C++ class: class Tree { public: Node *head; };
If I have a simple class setup like this: class MyClass { private string
I got this simple cache class setted up as a library in the Codeigniter:
Suppose you have a simple class like this: class foo{ private: int* mData; int

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.