GV

GeezerVison

The World Wide Web, restored to 800 pixels of glory.

Home|About|Gaming cabinet|Archives|How it works|Starter sites

On this site

  • Sign in
  • ActionsCI/CD and automation
  • CodespacesCloud development environments
  • All Features
  • Documentation
  • Training
  • Certifications
  • Build with Copilot
  • Customize Copilot
  • Integrations
  • Trending repos
  • GitHub Sponsors
  • Developer articles
  • Enterprises

This view

  • Original page
  • New address

GeezerVison is showing github.com — GitHub - feehsu/java-fileReadWrite

BranchesTags
Open more actions menu

Latest commit

 

History

5 Commits
5 Commits

Folders and files

NameName
Last commit message
Last commit date
bin
bin
 
 
src
src
 
 
.gitignore
.gitignore
 
 
README.md
README.md
 
 

Repository files navigation

Java Reader and Write Files

Example Application: Reader (FileReader) and Write (FileWriter) files.

Read File

Imports

import java.io.BufferedReader;
import java.io.File;
import java.io.FileReader;
import java.io.IOException;

Check file exists

⚠️ Creates a new File instance by converting the given pathname string into an abstract pathname. If the given string is the empty string, then the result is the empty abstract pathname.

File file = new File(FILE);

if (file.exists()) {
	//TODO
} else {
	//TODO
}

Read file

⚠️ Need add throws declaration or surround with try/catch;

String FILE = "YOUR_LOG.log";

FileReader reader = new FileReader(FILE);
BufferedReader buffer = new BufferedReader(reader);

String line = null;

while ((line = buffer.readLine()) != null) {
	//TODO
	System.out.printf("%s\n", line);
}

⚠️ Closes the stream and releases any system resources associated withit.

buffer.close();

See the implementation: project

Write File

Imports

import java.io.BufferedWriter;
import java.io.File;
import java.io.FileWriter;
import java.io.IOException;

Check file exists

⚠️ Creates a new File instance by converting the given pathname string into an abstract pathname. If the given string is the empty string, then the result is the empty abstract pathname.

String FILE = "YOUR_LOG.log";

File file = new File(FILE);

if (file.exists()) {
	//TODO
} else {
	//TODO
}

Write File

⚠️ Need add throws declaration or surround with try/catch;

String content = "Lorem ipsum dolor sit amet, consectetur adipiscing elit.";

String FILE = "YOUR_LOG.log";
FileWriter writer = new FileWriter(FILE);
BufferedWriter buffer = new BufferedWriter(writer);

buffer.write(content);

System.out.println("Success! You file is saved!");

⚠️ Closes the stream and releases any system resources associated withit.

buffer.close();

See the implementation: project

Exceptions

  • IOException

Some links for more in depth learning

  • JAVA
  • JAVA PRINT;
  • JAVA SWITCH CASE;
  • JAVA IF/ELSE;
  • JAVA ARITHMETIC;

About

No description or website provided.

Topics

buffer-readerbuffer-writereclipsejavajava-readerjava-writerlogneatbeansreaderwriter

Resources

Readme
Activity

Stars

0 stars

Watchers

1 watching

Forks

0 forks
Report repository

Releases

Packages

Used by

Contributors

Languages

You are visitor 01402520 — GeezerVison does not store the pages you look up.
Best viewed with Netscape Navigator 4.7 or Internet Explorer 6 at 800×600. No cookies required.