| | |
String to file name
Please support our Java advertiser: Programming Forums - DaniWeb Sister Site
![]() |
•
•
Join Date: Apr 2006
Posts: 8
Reputation:
Solved Threads: 0
hi all!
i want to delete a file/directory in java, the delete().depends on other programs which uses file name as string.but for me to delete the file,the name must be a File.
that is what i have realized as when i use string it does not recognized some methods,like List etc
how can i go about it.
note:
1.the program should not limit to only file but should also delete directory if the thing to be deleted is directory.
2.the file should be deleted despite any security measure like:write protected etc
please help
i want to delete a file/directory in java, the delete().depends on other programs which uses file name as string.but for me to delete the file,the name must be a File.
that is what i have realized as when i use string it does not recognized some methods,like List etc
how can i go about it.
note:
1.the program should not limit to only file but should also delete directory if the thing to be deleted is directory.
2.the file should be deleted despite any security measure like:write protected etc
please help
well... if you have the name of the file in a String, for instance
take a look at the api's of the File-class. especially take a good look at the constructors.
for deleting that directory, you'll have to use recursivety to first delete all the files in that directory (and any subdirectories)
Java Syntax (Toggle Plain Text)
String fileName = "input.txt";
take a look at the api's of the File-class. especially take a good look at the constructors.
for deleting that directory, you'll have to use recursivety to first delete all the files in that directory (and any subdirectories)
•
•
Join Date: Sep 2008
Posts: 1,595
Reputation:
Solved Threads: 201
http://java.sun.com/javase/6/docs/ap...va.lang.String)
That might be of interest to you. I'm pretty sure if there is some security measure, you aren't going to be allowed to delete the file. That is, after all, the point... right?
That might be of interest to you. I'm pretty sure if there is some security measure, you aren't going to be allowed to delete the file. That is, after all, the point... right?
Last edited by BestJewSinceJC; Dec 31st, 2008 at 11:26 am.
•
•
Join Date: Apr 2006
Posts: 8
Reputation:
Solved Threads: 0
CLARIFICATION TO STRING TO FILE
bestjew:thanks but.
the program should be able to delete the directory or file from command prompt;you enter the name of the file and it should be able to be deleted.note.the name of the dir/file should not be appearing in the code.
in short,i should be able to create and delete without code modification.
reading an entry from keyboard,the format accepted are string,integer etc but not type file.
bestjew:thanks but.
the program should be able to delete the directory or file from command prompt;you enter the name of the file and it should be able to be deleted.note.the name of the dir/file should not be appearing in the code.
in short,i should be able to create and delete without code modification.
reading an entry from keyboard,the format accepted are string,integer etc but not type file.
Yes you can accept a string as an input and then convert this string to a
But remember the path you specify on the command line should either be an absolute path or you should be running the program from the same directory, where the file/directory to be deleted exists, for this to work.
EDIT : We would certainly like you doing some homework of your own, it seems you haven't gone through the
File type. There is a contructor in the File that allows this. java Syntax (Toggle Plain Text)
public class DeleteFile{ public static void main(String [] args){ // Pass the first argument which is a filename to the constructor. File deleteFile = new File(args[0]); // code to delete file goes here. } }
But remember the path you specify on the command line should either be an absolute path or you should be running the program from the same directory, where the file/directory to be deleted exists, for this to work.
EDIT : We would certainly like you doing some homework of your own, it seems you haven't gone through the
File class documentation at all. Last edited by verruckt24; Jan 1st, 2009 at 7:40 am.
Get up every morning and take a look at the Forbes' list of richest people. If your name doesn't appear.... GET TO WORK !!!
•
•
•
•
EDIT : We would certainly like you doing some homework of your own, it seems you haven't gone through the File class documentation at all.
![]() |
Similar Threads
- compare string from file (Python)
- pls Help!! how to search for string in a file with C# and Web Services?? (C#)
- pls Help!! how to search for string in a file with C# and Web Services?? (RSS, Web Services and SOAP)
- Writing string to a file (Java)
- How to search for a string in a file (C#)
- sort string in file txt (C++)
- assigning a string from a file to a variable (C++)
- Using printf with a file (C++)
Other Threads in the Java Forum
- Previous Thread: Base 64 Decoding
- Next Thread: fixing position of awt objects in java
| Thread Tools | Search this Thread |
actuate android api applet application applications array arrays automation balls bank binary bluetooth business c++ chat class classes clear client code codesnippet collections component coordinates database defaultmethod development dice doctype dragging ebook eclipse error formatingtextintooltipjava fractal froglogic game givemetehcodez graphics gui hql html ide image infinite ingres input integer intersect invokingapacheantprogrammatically j2me java javaprojects jni jpanel julia linux list loop looping map method methods mobile mysql netbeans newbie openjavafx parameter php print problem program programming project recursion repositories scanner screen scrollbar server set size sms sort sorting sql sqlserver state storm string sun superclass swing swt text-file threads tree windows






