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

  • SEARCH
  • Home
  • 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 8730309
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 13, 20262026-06-13T08:59:42+00:00 2026-06-13T08:59:42+00:00

I have this java code that renames a file (or directory). There is a

  • 0

I have this java code that renames a file (or directory). There is a problem on Linux when I use some special characters, it works on Windows with these special characters. The way I try it is like this:
In windows

  • I create a direcotory called “326½_6”

  • I build a jar-file, and call it (java -jar) directly in the windows cmd (or linux shell), first param is the directory above, second param is a path to a new directory.
    This works

I then transfer the directory to a Linux server using SFTP (WinSCP). I repeat the steps above, but it doesn’t work. I get this output:

Moving /home/user/testarea/326�_6/ to /home/user/testarea/test5/

— could not perform rename ——-

Is there anyway to make this work on a Linux machine???

the code:

  public static void main(String [] args) {
    String source = args[0];
    String dest = args[1];
    System.out.println(" - Moving " + source + " to " + dest);

    File sourceFile = new File(source);
    File destinationFile = new File(dest);

    if (!sourceFile.renameTo(destinationFile)) {
        System.out.println("--- could not perform rename -------");
    }

    System.out.println("Finished moving");
 }

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-06-13T08:59:43+00:00Added an answer on June 13, 2026 at 8:59 am

    It looks like Java on Linux is expecting file and directory names to be encoded in UTF-8, but when WinSCP creates the directory it encodes the name in latin1 or something similar, and the new name is not valid in UTF-8. Apparently this was the default behavior for WinSCP, the newer versions use UTF-8 by default.

    An easy solution to make Java use the same encoding that SFTP used when creating the directory. This is done by changing the locale when running the JVM:

    LANG=en_US.iso8859_1 java -jar YourProgram.jar
    

    The locale en_US.iso8859_1 has to exist for this to work, though. You might be able to install new locales from the package repositories of your distribution. If not, you can read about how to define a locale with a specific encoding (and about this file name problem in general) in my blog.

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

Sidebar

Related Questions

I have a java code that looks like this: //UI thread //Some code Job
I have some java code that looks similar to this: private void startServer() throws
i have a question , i have this timer code in java that when
I have a cross-language problem regarding md5 :). I have this code in Java:
I have a bit of Java code that outputs an XML file to a
i have this problem: I have created a bash script that performs some tasks.
I have a java code that use a stored procedure for that it is:
I have this java code that, using apache jena api, queries the pizza ontology
I have this working java code that serve as the datasource: public final class
i have this java code: ArrayList<MessageMap> ids = getNewMail(UserID, type, maxIdMessage); Message[] message =

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.