Win a copy of Building Blockchain Apps this week in the Cloud/Virtualization forum!
  • Post Reply Bookmark Topic Watch Topic
  • New Topic
programming forums Java Mobile Certification Databases Caching Books Engineering Micro Controllers OS Languages Paradigms IDEs Build Tools Frameworks Application Servers Open Source This Site Careers Other all forums
this forum made possible by our volunteer staff, including ...
Marshals:
  • Campbell Ritchie
  • Paul Clapham
  • Liutauras Vilda
  • Knute Snortum
  • Bear Bibeault
Sheriffs:
  • Devaka Cooray
  • Jeanne Boyarsky
  • Junilu Lacar
Saloon Keepers:
  • Ron McLeod
  • Stephan van Hulst
  • Tim Moores
  • Carey Brown
  • salvin francis
Bartenders:
  • Tim Holloway
  • Piet Souris
  • Frits Walraven

File

 
Ranch Hand
Posts: 135
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
what is the difference between
File f = new File("a,txt");
and
f.createNewFile()
where a.txt file created?
Thanks
 
Sheriff
Posts: 9671
42
Android Google Web Toolkit Hibernate IntelliJ IDE Spring Java
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Errata: Change

File f = new File("a,txt");

to

File f = new File("a.txt");

. After that when you write that statement, the object will start referring to a PATH which has a.txt in the end. It is not necessary that the file a.txt is present. But when you call

f.createNewFile()

then if a.txt doesn't exists, it will be created. So you can be sure that after call to createNewFile, the object f refers to a file a.txt...
 
Ranch Hand
Posts: 952
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Ofcourse when f.createNewFile() is called then.

File is just a class, if you call new File("filename"), it just creates an object of file class. But if you want to create filename file in the system, you have to call File.createNewFile().

Any doubt???
 
siddharth das
Ranch Hand
Posts: 135
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
what is the meaning of
File file = new File(directory,�f�);
 
Java Cowboy
Posts: 16084
88
Android Scala IntelliJ IDE Spring Java
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Lookup class File in the API documentation.
 
Greenhorn
Posts: 6
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
It will create a instance of file named �f� at the �directory� Directory on the heap.
To persist it, first you need to check - either directory folder should be there OR you need to call directory.mkdir(). And then you need to call file.createNewFile().
 
The happiness of your life depends upon the quality of your thoughts -Marcus Aurelius ... think about this tiny ad:
Java file APIs (DOC, XLS, PDF, and many more)
https://products.aspose.com/total/java
  • Post Reply Bookmark Topic Watch Topic
  • New Topic
Boost this thread!