File Handling In JAVA

File Handling In JAVA

Share It With Your Firends:

Java File Handling: In this video, we will see how files are handled in the Java programming language. In this video of our java complete course, we will see how java programming can be leveraged to read, write, create and delete files.

import java.io.File;
import java.io.FileNotFoundException;
import java.io.FileWriter;
import java.io.IOException;
import java.util.Scanner;

public class tut15 {
    public static void main(String[] args) {
        // Create a file
//        File myFile = new File("Hello.txt");
//        try {
//            myFile.createNewFile();
//        } catch (IOException e) {
//            throw new RuntimeException(e);
//        }

        // Write In a file

//        try {
//            FileWriter fileWriter = new FileWriter("Hello.txt");
//            fileWriter.write("Hello World, I am a Programmer.");
//            fileWriter.close();
//        } catch (IOException e) {
//            throw new RuntimeException(e);
//        }

        // Read in a file

//        File myFile = new File("Hello.txt");
//        try {
//            Scanner sc = new Scanner(myFile);
//            while (sc.hasNextLine()) {
//                String line = sc.nextLine();
//                System.out.println(line);
//            }
//            sc.close();
//        } catch (FileNotFoundException e) {
//            throw new RuntimeException(e);
//        }

        // Delete a File

        File myFile = new File("Hello.txt");
        if (myFile.delete()){
            System.out.println("Deleted : " + myFile.getName() );
        }
        else System.out.println("Some error occurred");

    }
}

Share It With Your Friends

Leave a Reply

Recent Posts

  • All Post
  • A.I.
  • AI
  • c
  • c++
  • computer
  • cryptocurrency
  • database
  • digital marketing
  • finance
  • hacking
  • HTML
  • java
  • Marketing
  • network
  • other
  • programming
  • python
  • react
  • social
  • Tools
  • Uncategorized
  • web devlopment
    •   Back
    • drawing In Python
DIY AI Voice Assistant In Python

September 8, 2023

Build your own AI assistant with Python! Learn to recognize voice commands, generate responses, and more. Create your virtual companion…

share it

Recent Posts

  • All Post
  • A.I.
  • AI
  • c
  • c++
  • computer
  • cryptocurrency
  • database
  • digital marketing
  • finance
  • hacking
  • HTML
  • java
  • Marketing
  • network
  • other
  • programming
  • python
  • react
  • social
  • Tools
  • Uncategorized
  • web devlopment
    •   Back
    • drawing In Python

Additional Content

CodeWithAM

Lorem ipsum dolor sit amet, consectetur adipiscing elit. Ut elit tellus luctus.

Products

Automated Chatbot

Data Security

Virtual Reality

Communication

Support

Services

FAQ's

Privacy Policy

Terms & Condition

Team

Contact Us

Company

About Us

Services

Features

Our Pricing

Latest News

© 2023 Codewitham