🕵️ SicherheitslückenHak5: Hackers Just Poisoned the Rust Supply Chain | Threat Wire(01.09.2026 um 14:00 Uhr)
🕵️ SicherheitslückenHak5: Hackers Found a Way Into Humanoid Robots | Threat Wire(04.09.2026 um 15:04 Uhr)
🔧 AI Nachrichten Bits und so #1021 (Passwort für Laufwerk)(31.08.2026 um 22:15 Uhr)
🔧 AI Nachrichten Bits und so #1022 (Wie Weißbier)(06.09.2026 um 20:39 Uhr)
🍏 iOS / Mac OSHue-App 6.0 ist da: das sind die Neuerungen(07.09.2026 um 17:21 Uhr)
🕵️ SicherheitslückenHak5: Hackers Just Poisoned the Rust Supply Chain | Threat Wire(01.09.2026 um 14:00 Uhr)
🕵️ SicherheitslückenHak5: Hackers Found a Way Into Humanoid Robots | Threat Wire(04.09.2026 um 15:04 Uhr)
🔧 AI Nachrichten Bits und so #1021 (Passwort für Laufwerk)(31.08.2026 um 22:15 Uhr)
🔧 AI Nachrichten Bits und so #1022 (Wie Weißbier)(06.09.2026 um 20:39 Uhr)
🍏 iOS / Mac OSHue-App 6.0 ist da: das sind die Neuerungen(07.09.2026 um 17:21 Uhr)

🔧 Programmierung 🕛 kürzlich 3 Min Lesezeit
0

File handling in java

↗ Quelle (dev.to)
🗣️ Stimme:
📑 Inhaltsübersicht

in java, file handling means working with files like create, read, write, update, deleting them.



it helps to store program informations, if needed it can access after program executed also.



why file handling needed?




  • to store data permanently instead of keeping only on the memory.

  • to read and write files from/to for later use.

  • to share data between different program or system.


  • to organize and manage large data efficiently.




to support file handling, java provides The File class in the java.io Package.



file handling class File, FileReader, FileWriter, BufferedReader, BufferedWriter.



1. File class

File class is used to represent a file or directory path in java.



The File class can:




  • Create file and directories

  • check whether a file exists

  • Get file information(name, size, path, etc)

  • delete file and directories



note: File class does not contains read or write.




CODE
import java.io.File;

public class Practice {
public static void main(String[] args) {
File file = new File("sample.txt");
file.createNewFile();
}
}






common File class methods :




  • createNewFile()

  • exists()

  • delete()

  • isFile()

  • getName()

  • getPath()

  • list()

  • getAbsolutePath()

  • getCanonicalPath()



getAbsolutePath() → Returns full path as it is.

getCanonicalPath() → Returns simplified real path by removing . and .. .





2. FileWriter Class



in java, filewriter is a stream class. it is used to write text data for file.



Why File Writer?




  • write data in text file

  • update existing file

  • create new file and write



Constructor

1. Write Mode




CODE
FileWriter fw = new FileWriter("sample.txt");






Delete existing data and write new data.



2. Append Mode




CODE
FileWriter fw = new FileWriter("sample.txt", true);









CODE
import java.io.FileWriter;
import java.io.IOException;

class Main {
public static void main(String[] args) throws IOException {

FileWriter fw = new FileWriter("sample.txt");

fw.write("Hello Java");

fw.close();

System.out.println("Data Written");
}
}






old data will can't delete and new data will add on the end of the old data.



Methods

write(String s) => used to write string

write(int c) => write single character

flush() => buffers data send yo file

close() => close the file





3. BufferedWriter Class



in java , BufferedWriter first data store in buffer then one times write in file.



Advantage




  • Faster then FileWriter

  • good for write Large amount of data

  • is there newLine() method



CODE
import java.io.*;

class Main {
public static void main(String[] args) throws Exception {

BufferedWriter bw =
new BufferedWriter(new FileWriter("sample.txt"));

bw.write("Hello Java");
bw.newLine();
bw.write("Welcome");

bw.close();

System.out.println("Data Written");
}
}







4. FileReader Class



FileReader is a character stream class. it is used to read characters from the text file.



why FileReader?




  • read data from text file

  • read character by character

  • it is commonly used for read text files (.txt)



Constructor




CODE
FileReader fr = new FileReader("sample.txt");






sample.txt file open in read mode.



important methods

read() => read one character

close() => file will close




CODE
import java.io.FileReader;

class Main {
public static void main(String[] args) throws Exception {

FileReader fr = new FileReader("sample.txt");

int ch = fr.read();

System.out.println((char) ch);

fr.close();
}
}






How read() Works




CODE
int ch = fr.read();







  • if read find the character return that ASCII/Unicode value.

  • if finds the end, return -1.






5. BufferedReader Class



BufferedReader is used to read text fastly from the text file.






Why BufferedReader?




  • File read line by line.

  • speed better then FileReader.

  • better for read large file.

  • is there readLine() method.



Important Methods





  • read() => read one character


  • readline => read one line


  • close() => close the Stream




CODE
import java.io.*;

class Main {
public static void main(String[] args) throws Exception {

BufferedReader br =
new BufferedReader(new FileReader("sample.txt"));

String line=br.readLine();

while (line!= null) {
System.out.println(line);
}

br.close();
}
}


Vollständiger Original-Bericht
Ausführliche Details, Code-Beispiele & Hersteller-Stellungnahme auf dev.to.
↗ Original-Artikel auf dev.to lesen
Wie bewertest du diesen Beitrag?
1 Klick Feedback
Teilen mit Netzwerk & Team:

Community-Analysen & Experten-Meinungen 0

Verfasse deine eigene Analyse, teile Workarounds oder diskutiere diesen Vorfall im Blog.
Noch keine Community-Analyse verfasst. Markiere einen Textabschnitt oder klicke oben auf Eigene Analyse verfassen“!
Community Pulse: Relevanz-Einschätzung
1 Klick Experten-Votum
🔴 Akute Relevanz 0%
🟡 In Evaluierung 0%
🟢 Keine Auswirkung 0%
Spannende Innovation 0%
Verwandte Story-Cluster & Quellen (Vektor-KI)
Port 8095 Engine
1 Quelle
Hackers Just Poisoned the Rust Supply Chain | Threat Wire
1 Quelle
Hackers Found a Way Into Humanoid Robots | Threat Wire
1 Quelle
Bits und so #1021 (Passwort für Laufwerk)
Ähnliche Beiträge
🔍 Verwandte News

Auch interessante Nachrichten File handling in java

Thematisch verwandte Begriffe: File, handling, java · 6 Treffer

Laden...

Videos werden geladen ...

Laden...

Beiträge werden geladen ...

Laden...

Videos werden geladen ...

Laden...

Beiträge werden geladen ...

Laden...

Videos werden geladen ...

Laden...

Beiträge werden geladen ...

Laden...

Videos werden geladen ...