• Post Reply Bookmark Topic Watch Topic
  • New Topic

problem with folder deletion in linux from Servlet  RSS feed

 
Neeraj Dhiman
Ranch Hand
Posts: 68
IBM DB2 Eclipse IDE Java
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
hi friends,
i am deleting some folder on linux server through a servlet request. but the path i am sending is treated as garbage or some specail character.

this
rm -r -f
is treated as
rm –r –f
in word editor

and in vi editor
rm -r -f
is treated as
rm âr âf


Any help. thanks in advance.
 
Victor M. Pereira
Ranch Hand
Posts: 50
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
As soon as you append it?

Have you tried using other classes or changing - to its unicode representation?
 
Neeraj Dhiman
Ranch Hand
Posts: 68
IBM DB2 Eclipse IDE Java
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
No as soon i append it, it is fine. Even it work in window server but on linux server there is problem.
i have used unicode like:


it works fine in windows but linux same problem;
is there any problem with linux setting?
 
Victor M. Pereira
Ranch Hand
Posts: 50
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
I only found a page that claims the following:

"Before you switch to UTF-8 under Linux, update your installation to a recent distribution with up-to-date UTF-8 support. This is particular the case if you use an installation older than SuSE 9.1 or Red Hat 8.0. Before these, UTF-8 support was not yet mature enough to be recommendable for daily use.

Red Hat Linux 8.0 (September 2002) was the first distribution to take the leap of switching to UTF-8 as the default encoding for most locales. The only exceptions were Chinese/Japanese/Korean locales, for which there were at the time still too many specialized tools available that did not yet support UTF-8. This first mass deployment of UTF-8 under Linux caused most remaining issues to be ironed out rather quickly during 2003. SuSE Linux then switched its default locales to UTF-8 as well, as of version 9.1 (May 2004). It was followed by Ubuntu Linux, the first Debian-derivative that switched to UTF-8 as the system-wide default encoding. With the migration of the three most popular Linux distributions, UTF-8 related bugs have now been fixed in practically all well-maintained Linux tools. Other distributions can be expected to follow soon. " (UTF - 8 and Unicode FAQ for Unix/Linux)
 
Maki Jav
Ranch Hand
Posts: 449
  • Likes 3
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Hi,

Why don't you use File object and delete() method on that object?
It will spare you all the headache...


Maki Jav
 
Rob Spoor
Sheriff
Posts: 21095
85
Chrome Eclipse IDE Java Windows
  • Likes 1
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
I agree with Maki. Using rm -r -f is a dangerous command; if you add a space between the first / and the rest of the path and you run this command as root, you can kiss your installation goodbye. A recursive file deletion method will also get your intended results but is safer since you work with File objects; adding that space would try to find file "/ myfolder/mywrk/myattach/xxx" which would just cause nothing to be deleted.
 
Neeraj Dhiman
Ranch Hand
Posts: 68
IBM DB2 Eclipse IDE Java
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
okay thats fine. Although this is a good practise. but we have a different agent which take care of deletion of files during the free hours on the server. so we adopt this one.
so we just provide information to that agent.
 
Tim Holloway
Bartender
Posts: 18716
71
Android Eclipse IDE Linux
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
I don't normally use OS-level commands to do this. For one thing, they're not portable, for another, it's just a pain to spawn out a complete exec environment. So I just have a class that does it for me using the java.io.file package.

The gist of the algorithm is as follows:



The actual code is slightly more complex to allow for non-file/directory "files", exceptions, and possible failures to delete, but that's the essence of it.
 
Rob Spoor
Sheriff
Posts: 21095
85
Chrome Eclipse IDE Java Windows
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Although the method is called delete(), not remove()
 
Neeraj Dhiman
Ranch Hand
Posts: 68
IBM DB2 Eclipse IDE Java
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Using "File Object" is a good one. but i can't delete my files like this due to some reasons.
i create a file to check what is going on. when i write in the file in linux envoirnment the spacial character like above (problem) i found.
In windows, its fine. i think its the problem of writing the file in linux environment.
 
Neeraj Dhiman
Ranch Hand
Posts: 68
IBM DB2 Eclipse IDE Java
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
this was an encoding issue. now solved.

Thanks All
 
  • Post Reply Bookmark Topic Watch Topic
  • New Topic
Boost this thread!