Java Topics
HubJava Collections FrameworkCollections Practice ProgramsComparable vs ComparatorGenericsIteratorArrayListLinkedListStackVectorHashMapHashtableLinkedHashMapTreeMapArrayDequeDeque Double-Ended QueuePriorityQueueHashSetLinkedHashSetTreeSetAdapter PatternBuilder PatternFactory PatternMVC PatternObserver PatternSingleton PatternDynamic ProgrammingGraphHashingHeapLinked List DSAQueue DSARecursionSearching AlgorithmsSorting AlgorithmsStack DSATime ComplexityTreesException Handling Best PracticesCustom ExceptionException Hierarchyfinally BlockException Handlingthrow aur throwstry-catchBuffered StreamsByte StreamsCharacter StreamsDeserializationFile ClassJava NIO New I/OSerializationArrays in JavaArray OperationsArray Practice ProgramsArray Interview QuestionsJagged ArrayMulti-Dimensional ArraysOne Dimensional Arraybreak aur continuedo-while Loopfor Loopif-else StatementsNested Loopsswitch-case Statementwhile LoopJava Compilation ProcessJava ki FeaturesPehla Java ProgramHistory of JavaJava EditionsJava Program StructureJDK, JRE aur JVMJava Kya Hai?Immutable StringsString Class in JavaString Interview QuestionsString MethodsString Practice ProgramsStringBufferStringBuilderComments in JavaData Types in JavaIdentifiers in JavaInput & Output in JavaJava KeywordsOperators in JavaType Casting in JavaVariables in JavaJava Coding Interview QuestionsCollections Interview QuestionsCore Java Interview QuestionsJDBC Interview QuestionsMultithreading Interview QuestionsOOPs Interview QuestionsSpring Framework Interview QuestionsJava 8 Date/Time APIDefault aur Static Methods in InterfaceFunctional InterfaceLambda ExpressionMethod ReferenceOptional ClassStream APIBatch ProcessingCallableStatementJDBC ArchitectureJDBC — Java Database ConnectivityJDBC Practice ProjectsMySQL ConnectionPreparedStatementResultSetStatement InterfaceTransaction ManagementCreating ThreadsDaemon ThreadExecutor FrameworkInter-Thread CommunicationMultithreading Practice ProgramsRunnable InterfaceSynchronizationThread ClassMultithreading IntroductionThread Life CycleThread PriorityJava Cheat SheetImportant Formulas & Key ConceptsImportant Java ProgramsJava Quick RevisionAbstract ClassAbstractionAnonymous ClassClass and ObjectConstructorEncapsulationInheritanceInner ClassInterfaceMethod OverloadingMethod OverridingObject ClassObject CloningObject-Oriented Programming OOPPolymorphismstatic Keywordsuper Keywordthis KeywordWrapper ClassesArray Practice ProgramsBasic Java Practice ProgramsCollection Practice ProgramsJDBC Practice ProgramsMultithreading Practice ProgramsOOPs Practice ProgramsPlacement Coding QuestionsString Practice ProgramsBanking SystemChat ApplicationE-Commerce Backend — Spring Boot REST APIEmployee Management SystemLibrary Management SystemSpring Boot Fullstack ProjectStudent Management SystemCookies in ServletExpression Language ELGenericServletHttpServletJavaServer Pages JSPJSP TagsMVC ArchitectureHttpServletRequest & HttpServletResponseServlet IntroductionServlet Life CycleSession TrackingDependency InjectionSpring BeansSpring CoreSpring FrameworkAPI GatewaySpring Cloud Config ServerDocker DeploymentEureka Server — Service DiscoverySpring Boot CRUD ApplicationException Handling in Spring BootJWT AuthenticationREST API in Spring BootSpring SecuritySpring BootSpring Data JPAValidation in Spring Boot
Buffered Streams
Last Updated : 26 May, 2026
title: Buffered Streams in Java
File Handling42 words4 headingsExamples included
title: Buffered Streams in Java description: BufferedReader aur BufferedWriter for performance
Buffering se I/O performance improve hoti hai — disk reads kam hote hain.
BufferedWriter
java exampleWoHoTech
try (BufferedWriter bw = new BufferedWriter(new FileWriter("data.txt"))) {
bw.write("Line 1");
bw.newLine(); // Platform-independent newline
bw.write("Line 2");
bw.newLine();
bw.write("Line 3");
// flush() hota hai automatically on close
}BufferedReader — Line by line read
java exampleWoHoTech
// readLine() — Most common way to read text files
try (BufferedReader br = new BufferedReader(new FileReader("data.txt"))) {
String line;
while ((line = br.readLine()) != null) {
System.out.println(line);
}
}
// Java 8+ lines() — Stream
try (BufferedReader br = new BufferedReader(new FileReader("data.txt"))) {
br.lines()
.filter(line -> !line.isEmpty())
.forEach(System.out::println);
}Files.readAllLines() — Simplest (Java 7+)
java exampleWoHoTech
import java.nio.file.*;
import java.nio.charset.StandardCharsets;
List<String> lines = Files.readAllLines(Path.of("data.txt"), StandardCharsets.UTF_8);
lines.forEach(System.out::println);
// Write all lines
List<String> content = Arrays.asList("Line 1", "Line 2", "Line 3");
Files.write(Path.of("output.txt"), content, StandardCharsets.UTF_8);Performance Comparison
java exampleWoHoTech
// Without buffering — slow (disk hit every read)
FileReader fr = new FileReader("large.txt");
// With buffering — fast (reads chunk at a time)
BufferedReader br = new BufferedReader(new FileReader("large.txt"), 8192); // 8KB bufferExam Focus
Revise definitions, diagrams, examples, and short-answer points for Buffered Streams.
Interview Use
Prepare one clear explanation, one practical example, and one common mistake for this Java topic.
Search Terms
java, java programming, core java, java master course, java notes, master, course, file
Related Java Topics
Continue learning this concept
File HandlingByte Streamstitle: Byte Streams in JavaFile HandlingCharacter Streamstitle: Character Streams in JavaFile HandlingDeserializationtitle: Deserialization in JavaFile HandlingFile Classtitle: File Class in JavaFile HandlingJava NIO New I/Otitle: NIO Package in JavaFile HandlingSerializationtitle: Serialization in Java