File APIs for Java Developers
Manipulate DOC, XLS, PPT, PDF and many others from your application.
http://aspose.com/file-tools
The moose likes I/O and Streams and the fly likes String format to create directory in Unix Big Moose Saloon
  Search | Java FAQ | Recent Topics
Register / Login
JavaRanch » Java Forums » Java » I/O and Streams
Reply Bookmark "String format to create directory in Unix" Watch "String format to create directory in Unix" New topic
Author

String format to create directory in Unix

Nirmal Mukundan
Greenhorn

Joined: Feb 21, 2007
Posts: 24

Hi

I have an issue in writing a file to a server path.
The problem is like this:

I have a job that runs in the Unix environment to get an extract and write that to a file in the server location. The path that I have configured to write the file ..say "abc.csv" is in
/projects/distrib/extracts/XXX/éxtract.

The problem here is when the file is been created by the job the final folder is created as ?xtract. The é is been converted. But if I try to create the folder with same name manually in the same machine through file zilla the folder gets created.

Could you please help me to identify an correct the issue.

I had tried MimeUtility.encodeText("éxtract"); But didnt work..it encoded the text to something else.

Regards
Nirmal Mukundan
Greenhorn

Joined: Feb 21, 2007
Posts: 24

Hi,

Does any one have the solution to this.
I tried to put the following code

logger.info("Default Charset=" + Charset.defaultCharset()); -- output is US-ASCII

String path = "/projects/distrib/extracts/XXX/éxtract";
byte[] bytes3 = path.getBytes("UTF-8");
System.out.println("UTF-8 decoded: "+new String(bytes3)); -- output is /projects/distrib/extracts/XXX/?xtract

Please help
Ireneusz Kordal
Ranch Hand

Joined: Jun 21, 2008
Posts: 423
Is your job is a java program ?
How this job is fired, by cron ?
Is the file that contains the directory name is encoded in utf8 or is a plain ascii or something else ?
What is a value of LANG variable in the execution environment of your job ?
Nirmal Mukundan
Greenhorn

Joined: Feb 21, 2007
Posts: 24

The program is a java program and is called from a swing client. This piece of code runs in the Unix environment.

When I gave System.getProperty("file.encoding") -- out put is ANSI_X3.4-1968

LANG value is C
Ireneusz Kordal
Ranch Hand

Joined: Jun 21, 2008
Posts: 423
Nirmal Mukundan wrote:The program is a java program and is called from a swing client. This piece of code runs in the Unix environment.

When I gave System.getProperty("file.encoding") -- out put is ANSI_X3.4-1968

LANG value is C


C and ANSI_X3.4-1968 is a plain ASCII encoding, it doesn't have é character
Check which code pages are supported by your system, a command locale -a writes all available locales,
use one that supports utf8.


You can test which settings are OK with this simple java program:


Nirmal Mukundan
Greenhorn

Joined: Feb 21, 2007
Posts: 24

Hi Ireneusz,

Thanks for the reply. Well we have moved to the new Linux machines recently. So could it be that the LANG settings have not been set properly.

Regards
Nirmal
Nirmal Mukundan
Greenhorn

Joined: Feb 21, 2007
Posts: 24

Hi Ireneusz,

Thanks for the reply. Well we have moved to the new Linux machines recently. So could it be that the LANG settings have not been set properly.
Today I tried with a sample program to create a directory in the same machine. Before executing the program, I did export LANG=fr_FR and this worked fine.

But I think this wont be right encoding..Is it?

Regards
Nirmal
Ireneusz Kordal
Ranch Hand

Joined: Jun 21, 2008
Posts: 423
Hi,

it seems that the job doesn't inherit the environment from the calling application and uses ANSI_X3.4-1968 as default charset.
Try to launch this job from the swing application with command: java -Dfile.encoding=utf8 jobname or java -Dfile.encoding=ISO-8859-1 jobname,
this should force jvm to use the proper encoding.

Regards.
 
 
subject: String format to create directory in Unix
 
Threads others viewed
creating directories...HELP
grant write access to folder in unix
Create a file at runtime
Restore Java project
How to debug jsp page
developer file tools