Results 1 to 13 of 13
Thread: Files
- 03-16-2011, 09:05 PM #1
Member
- Join Date
- Feb 2011
- Posts
- 9
- Rep Power
- 0
Files
Hello,
I am trying to create a file and then delete it. This code does create file a.txt, but won't delete it pls help me. And I would also like to know, if a file is deleted through a program, does it go to recycle bin??
RegardsJava Code:import java.io.FileWriter; import java.io.File; import java.io.Writer; import java.io.FileNotFoundException; import java.io.IOException; public class fileop { public static void main(String[] args) { Writer writer = null; try { String word = "hello"; File f1 = new File("a.txt"); writer = new BufferedWriter(new FileWriter(f1)); writer.write(word); f1.delete(); } catch (FileNotFoundException e) { e.printStackTrace(); } catch (IOException e) { e.printStackTrace(); } finally { try { if (writer != null) { writer.close(); } } catch (IOException e) { e.printStackTrace(); } } } }
Maya
-
try this to confirm what you are saying:
Java Code:boolean fileDeleted; fileDeleted = f1.delete(); System.out.println("File deleted? " + fileDeleted);
If the delete is successful, fileDeleted will = true; or false if unsuccessful.
- 03-16-2011, 10:12 PM #3
Member
- Join Date
- Mar 2011
- Posts
- 64
- Rep Power
- 0
Files deleted through Java does not go to the Recycle Bin. Recycle Bin / Un-delete etc are OS specific; Java is cross-platform. You have to implement a native OS call to implement those.
- 03-16-2011, 10:17 PM #4
Senior Member
- Join Date
- Jan 2011
- Location
- Belgrade, Serbia
- Posts
- 227
- Rep Power
- 3
Yes, and that means jni, so good luck
- 03-16-2011, 10:19 PM #5
Member
- Join Date
- Mar 2011
- Posts
- 64
- Rep Power
- 0
- 03-16-2011, 10:22 PM #6
Senior Member
- Join Date
- Jan 2011
- Location
- Belgrade, Serbia
- Posts
- 227
- Rep Power
- 3
My aplogies, I feel guilty so this is an example, I didn't try it but..
Scratch Where It's Itching : Weblog
-
Too complicated. Just make your own "recycle bin" e.g. copy items to a specified folder "dump" before it is deleted.
- 03-16-2011, 10:29 PM #8
Senior Member
- Join Date
- Jan 2011
- Location
- Belgrade, Serbia
- Posts
- 227
- Rep Power
- 3
-
- 03-16-2011, 10:36 PM #10
Senior Member
- Join Date
- Jan 2011
- Location
- Belgrade, Serbia
- Posts
- 227
- Rep Power
- 3
Actually it is...
-
Lol, thanks.
- 03-16-2011, 11:22 PM #12
Member
- Join Date
- Mar 2011
- Posts
- 64
- Rep Power
- 0
JNA is a little less painful than JNI. You don't have to code in another language.
Java Native Access (JNA): Pure Java Access to Native Libraries — Java.net
- 03-17-2011, 06:28 AM #13
Similar Threads
-
Convert avi, mpeg, wmv media files to .flv files in java code
By vinay1497 in forum New To JavaReplies: 8Last Post: 07-30-2010, 05:47 PM -
working with files (text files)
By itaipee in forum New To JavaReplies: 1Last Post: 02-24-2009, 11:38 AM -
Behaving text files like binary files
By Farzaneh in forum New To JavaReplies: 2Last Post: 08-27-2008, 03:20 PM -
Text and image files within jar files
By erhart in forum Advanced JavaReplies: 8Last Post: 01-19-2008, 04:43 AM -
how to convert mpeg files to .wav files
By christina in forum New To JavaReplies: 1Last Post: 08-06-2007, 04:14 AM


LinkBack URL
About LinkBacks
Reply With Quote

Bookmarks