In my last post I explained how to create files.
Today i
will resume from there.
Creating folders also can be done in a similar manner.
File fol1=new File("firstfolder");
The name of the folder that you want to create (firstfolder)
should be passed into the constructor of the File object "fol1" that we are
creating. Actually this will create only the name of the folder, to create the
actual folder we have to call the mkdir() method in our fol1 object.
fol1.mkdir();
This will create a folder called "firstfolder" in
the location where you save this java file.
If you want to create it in a different
location you can give that location as follows.
File fol1=new
File("E:/image/firstfolder");
Please note that "/" character should be used when
specifying a path in JAVA.
After compiling and running the program as follows
You will able to see the folder which you have created...:)
Ok...now let's see how can we create a file inside a folder.
Let's create a file called "firstfile.exe" inside the folder which we
have created.
In
this code I have only added two more lines...:)
File
file1=new File(fol1,"firstfile.txt");
When
creating a file inside a folder, as I mentioned in my first post we have to
first create a File object. The only difference here is we have to pass two
parameters in to the constructor of the
object that we are creating.
- First we have to mention the File object ("fol1") corresponding to the folder which we are going to create our file in. You should create this folder before creating the file.
- Secondly pass the name and the file type of the file that we wish to create ("firstfile.txt").
Even
you can use an excising folder for this. If you wish to do so, first you must
create a File object refering that folder.
ex:
File
myown=new File("E:/image/myfolder");
then
you can proceed as usual, in this case calling mkdir()
is not needed since we are not creating a new folder.
File
file1=new File(myown,"firstfile.txt");
file1.createNewFile();
After compling and running, you will able to see ur new
file created inside the folder which you specified.. :)
Ok...........
now let's see how to detete a file.
In deleting also, the first thing we have to do is
creating a File object which refers to the file which we want to delete.
Let's delete this "Desert.jpg" file in this
location
Here is the code written for that
After creating the File object "Des" which refers
to the file which we wish to delete, the delete() method
should be called.
Des.delete();
After compiling and running you will notice that the "Desert.jpg"
is no more there.....:)
Please note that by this method the file will be completely
deleted WITHOUT moving to the Recycle Bin..!!
Folders can also be deleted in a similar manner..... But you
will only able to delete folders which are EMPTY. You won't able to delete a
folder if it contains any files...!! You
must first delete the files inside it before deleting such folder...:)
Let's delete this "Foldername" folder which is
empty.
After compiling and running the following code, you will
note that it is no more....
That's all for this post............:)
Hope you have understood my explanation..
If you have any doubts on this post please feel free to
ask........I will answer them as much as possible..)
See You soon with another post.....
Bye for now...!
TC....:)
great work :)
ReplyDeleteThanks sis :)
ReplyDeletedon't u continue this?
ReplyDeleteGreat article!
ReplyDeleteThanks for Sharing!
Java Training in Bangalore
Excellent information Providing by your Article, thank you for taking the time to share with us such a nice article.
ReplyDeletedigital marketing course in hubli
This is excellent information. It is amazing and wonderful to visit your site. Thanks for sharing this information, this is useful to me...
ReplyDeleteLooking for the best ppc course in Bangalore, India? Learn PPC from Ranjan Jena, 10+ Years Expert Google Ads Trainer. 1000+ Students Trained @ eMarket Education, Koramangala, Bangalore.
Best Online Digital Marketing Courses in Bangalore, India
Best Digital Marketing Institute in Bangalore
ReplyDeleteReally nice and informative blog, keep it up. Thanks for sharing and I have some suggestions.
if you want to learn pyhton Programming, Join Now Python Training in Bangalore.
Here is a Website- Software Training in Bangalore | AchieversIT
This may help you to find something useful
nice informative post. Thanks you for sharing.
ReplyDeleteWordpress Development
Mobile App Development
This comment has been removed by the author.
ReplyDeleteIts very interesting.. Now you can check it up the best digital marketing company in trivandrum
ReplyDeletehttps://adsifymarketing.com/
good write up Social media marketing course in tamil
ReplyDeleteFacebook ads mastery course in tamil
Youtube ads mastery course in tamil
Wonderful content as always, this is very informative and interesting
ReplyDeleteBest Spoken English Classes in Chennai | Spoken English Training Institute in Chennai
Nice post, thanks for sharing.
ReplyDeleteMedicine for Hiv in India | Hiv Medicine in India | Best Hiv Medicine in India
Need to design 3D image Rendering for a purpose like Industrial modeling, Architectural Rendering, Medical Illustration, Product modeling and design, Interior Visualisation, Animation Video etc, at low cost with excellent quality. Get the work customized as expected, our professional team will outcome customer idea.
ReplyDelete3d rendering china
3d architectural rendering china
3d interior designs china
3d product rendering china
Such an ideal piece of blog. It’s quite interesting to read content like this. I appreciate your blog
ReplyDeleteBest Homecare Services in Bangalore
caregiver services in bangalore
Thanks for this amazing blog , it is very useful content for us
ReplyDeletekeep sharing this type of informtion if anyone is looking for the best training institute in nodia visit us.
Python Training Institute
data science training in noida
machine learning institute in noida
java training institute in noida
data science training in noida
very useful and informative blog.
ReplyDeletesearching for https://tamizhakarthic.com/social-media-marketing-training-courses-online/
Social Media Marketing Online
That was great to read. Thanks for the blog.
ReplyDeleteJava course in Pune