By using this site, you agree to our updated Privacy Policy and our Terms of Use. Manage your Cookies Settings.
454,646 Members | 1,336 Online
Bytes IT Community
+ Ask a Question
Need help? Post your question and get tips & solutions from a community of 454,646 IT Pros & Developers. It's quick & easy.

I want to create function that create files and check if is exists or not

P: 4
Expand|Select|Wrap|Line Numbers
  1.  File f = new File("C:\\TEST");
  2.     try{
  3.         if(f.exists()==false){
  4.             f.mkdir();
  5.         System.out.println("Directory Created");
  6.         }
  7.         else{
  8.         System.out.println("Directory is not created");
  9.         }
  10.     }catch(Exception e){
  11.         e.printStackTrace();
  12.        }

and i have this error : illegal start of type in the try statement ...

please help my friends
Nov 14 '12 #1
Share this Question
Share on Google+
2 Replies


P: 2
Hi


Expand|Select|Wrap|Line Numbers
  1. var dir = new DirectoryInfo(@"d:\Temp");
  2.             var file = new FileInfo(Path.Combine(dir.FullName, "file.txt"));
  3.             if (!file.Exists) // you may not want to overwrite existing files
  4.             {
  5.                 using (Stream stream = file.OpenWrite())
  6.                 using (StreamWriter writer = new StreamWriter(stream))
  7.                 {
  8.                     writer.Write("saeid");
  9.                 }
  10.             }
Nov 14 '12 #2

P: 2
temp Folder is Example folder that Exists in Drive d
Nov 14 '12 #3

Post your reply

Sign in to post your reply or Sign up for a free account.