• Tech Travel Hub is your one stop, ultimate tour guide to all things tech, travel, visas and digital nomads
  • Home
  • Blog
    • Technology
      • General Tech
      • Blogging
      • Java
    • Lifestyle
      • General Lifestyle
    • Travel
    • Educational
    • Business
  • About
  • Contact
Menu
  • Home
  • Blog
    • Technology
      • General Tech
      • Blogging
      • Java
    • Lifestyle
      • General Lifestyle
    • Travel
    • Educational
    • Business
  • About
  • Contact
View Blog
April 11, 2023April 11, 2023

File Concept Simplified In Java

File in Java:

File is an important concept while doing any I/O operation using java. Frequently to read and write to a storage we use file. This is placed inside Java.io package.

In UNIX operating system, there is no separate thing defined for files and directories. Java File IO concept is defined and implemented based on UNIX. Hence File IO operations are same for file and directories.

 

We can store values using variables and arrays but

  • The data is lost either when a variable goes out of scope or when the program is terminated.That means the storage is temporary.
  • It is difficult to handle large volume of data using variables and arrays.

To overcome these problems we can place the data to a secondary storage devices (like hard disk,floppy drive,pen drive etc ). The data stored in secondary devices are called persistent data.

A file is a collection of related records placed in a particular area of the disk.A record is composed of several fields and a filed is a group of characters.
Characters in java are Unicode characters composed of two bytes,each byte is having eight binary bits(0 or 1).Storing and managing data using file is known as file processing which includes tasks such as creating files,updating files and manipulation of data.Reading and writing of data in a file can be done at the level of bytes or characters or fields depending on requirements. The process of reading and writing objects is called Object serialization.

Class file is written here in details.Please take a look.

 

File f=new File("path\filename.txt");

This statement in java will not create a new file instead it will check if there is any physical file exists in the given path. If so it will simply point to that file.If not it will do anything.

File fl=new File("c:\test.txt");
System.out.println(fl.exist());
//this will simply return false
fl.createNewFile();
//This will create a file
System.out.println(fl.exist());
//Now it will return true

 

Similarly for directories also we can use the same commands…

File fl=new File("c:\test");
System.out.println(fl.exist());
//this will simply return false
fl.mkdir();
//This will create a directory inside C drive named as test
System.out.println(fl.exist());
//Now it will return true

Let us check the constructors available in file…

File f=new File(String FileName)
// Checks if a file is present in the current working directory
File f=new File(String subDirectory,string fileName)
//This will create a file in given directory
// if the path is not given as a part of FileName  
File f=new File(File SubDirectory,String FileName)
//This will create a file in the sub directory under current directory
// if the path is not given as a part of FileName

 

Important methods for file:

  • boolean exists() This method checks if the physical file is available or not. If that is available it returns true or else it returns false
  • boolean createNewFile() This method checks if the physical file is available or not. If it is available it will return false without creating a new one. Else it will create a new file with the name provided.
  • boolean mkdir()  Same as above.
  • boolean isFile()  If the file object points to a valid physical file then it returns true else it will return false.
  • boolean isDirectory() Same as above.
  • String[] list() It returns all files and subdirectories present in specific sub directory.
  • long length() It returns the number of character presents in a file.
  • boolean delete() if file object points to a physical file and is able to delete the same, it will return true else will return false.

 

Post navigation

Previous post
Next post

Umer Umer

Leave a Reply Cancel reply

Your email address will not be published. Required fields are marked *

Recent Posts

  • 5 Ultimate Dental Nightmares and How to Avoid Them
  • 7 Alarming Facts on Early And Late Dental Implant Complications
  • The Skinny Jean Is Dead: The 5 Denim Styles You Need Now
  • 5 Reasons Why The Demand For Digital Marketing Courses Is Unstoppable At This Moment?
  • 3 Delicious Facts About Cakes That Very Few People Know

Categories

  • Adventure
  • Agile Methodology
  • All world Tour
  • Android Development
  • Ansible
  • App
  • App Development
  • Artificial Intelligence
  • AWS
  • Bitcoin
  • BlockChain
  • Blogging
  • Box Packing
  • Business
  • business
  • Business Communication
  • buying guide
  • C
  • car
  • Care
  • Certification
  • Certification
  • Chatbot
  • cinema
  • Cloud Tech
  • Content Marketing
  • Corporate
  • covid-19
  • crucible
  • Cryptocurrency
  • Database
  • DevOps
  • DevOps
  • Digital Marketing
  • Drawing
  • Dress
  • Educational
  • Employment
  • Entertainment
  • Exceptions In Java
  • Fashion
  • Festivals
  • Finance
  • Fitness
  • Food
  • Game
  • Gift ideas
  • Groovy
  • Health
  • Health
  • home
  • home improvement
  • HR
  • IllegalThreadStateException in Java
  • India Tour
  • Instagram
  • Ios
  • ISO
  • Java
  • Javascript
  • job
  • Kids Section
  • Kitchen
  • Law
  • Life Style
  • Lifestyle
  • Lifestyle Home Improvement
  • Main Stories
  • Management
  • Mattress
  • Motorable
  • Movie
  • nursing
  • Pendrive
  • Perspective
  • Pet
  • Popular
  • Programming
  • Python
  • Relationships
  • Selenium
  • SEO
  • Skin
  • SOAPUI
  • Social Media
  • Social Media Marketing
  • Software
  • software development
  • Software Development Model
  • Software Engineering
  • Software Testing
  • Sports
  • Startup
  • T Robot
  • TDD
  • Tech
  • Tech News
  • Tech News
  • Technology
  • Tool
  • Tour Guide
  • Tour Guide
  • Travel
  • UFT
  • Uncategorized
  • USB Cable
  • VPN
  • Web Development
  • Wordpress
  • Yoga
  • Youtube

Tags

Instagram Instagram Marketing Marketing SEO Thoptv App

Categories

  • Tech
  • Travel
  • Visas
  • Digital Nomad
  • Tech
  • Travel
  • Visas
  • Digital Nomad

Publishing

If you would like to publish on our site, please email admin@techtravelhub.com

Quick Links

  • Home
  • Blog
    • Technology
      • General Tech
      • Blogging
      • Java
    • Lifestyle
      • General Lifestyle
    • Travel
    • Educational
    • Business
  • About
  • Contact
  • Home
  • Blog
    • Technology
      • General Tech
      • Blogging
      • Java
    • Lifestyle
      • General Lifestyle
    • Travel
    • Educational
    • Business
  • About
  • Contact

Contact

Tech Travel Hub LLC

Address:
8 The Green STE A
Dover
Delaware, 19901

Phone: +1 302 956 9948