September 07, 2010, 04:26:10 AM *
Welcome, Guest. Please login or register.
Did you miss your activation email?

Login with username, password and session length
  Home Help Media Affiliates Login Register  
Pages: [1]   Go Down
  Print  
Author Topic: Create a file if not exists  (Read 486 times)
0 Members and 1 Guest are viewing this topic.
Arkie
Javaforums.net Admin
Senior Member
*

Reputation: 16
Developer @ Javaforums.net
Offline Offline
Posts: 2620
Referrals: 13

WWW Awards
« on: June 06, 2009, 12:46:29 PM »

Code
GeSHi (java):
  1. /*--------------------------------------------------------------------------
  2. CheckFileExists.java
  3.  ******************
  4. By: HappyFace http://www.engineeringserver.com
  5. Contact: info [@] engineeringserver.com
  6. Version: 6/june/2009
  7. "*****************
  8. Description:
  9. checks if a file excists, if not create it
  10. To do:
  11. //----------------------------------------------------------------------*/
  12. package console;
  13.  
  14. import java.io.File;
  15. import java.io.IOException;
  16.  
  17. public class CheckFileExists {
  18.  
  19. public static void main(String[] args){
  20. String fileStr = "c:\\DefaultTextFile.txt";
  21. File f = new File(fileStr);
  22.  
  23. if(!f.exists()){
  24. try {
  25. f.createNewFile();
  26. System.out.println(fileStr + " created");
  27. } catch (IOException e) {
  28. e.printStackTrace();
  29. }
  30. }
  31. else{
  32. System.out.println(fileStr + " not created");
  33. }
  34. }
  35. }
  36.  
Created by GeSHI 1.0.7.20
Logged

Java and .NET developer

To students: It doesn't matter how hard you've studied; the material won't be on the exam anyway.

Fan of http://www.retardedweblogger.com
Oh man, too much stuff to do in so little time.

http://img222.imageshack....707/arkietomatoesmall.jpg
Blizzcon 2k9 Grubby and Cassandra Ng engaged ! <3
Triple D, eerste Denken Dan Doen
Javaforums.net :: a community about Java software development.
« on: June 06, 2009, 12:46:29 PM »

 Logged
Pages: [1]   Go Up
  Print  
 
Jump to:  

Your Ad Here
Powered by MySQL Powered by PHP Powered by SMF 1.1.10 | SMF © 2006-2009, Simple Machines LLC
TinyPortal v0.9.8 © Bloc
Valid XHTML 1.0! Valid CSS!
Page created in 0.189 seconds with 32 queries.

Google visited last this page Yesterday at 09:26:17 PM