--- id: java-bufferedwriter title: "Java BufferedWriter" category: "Programming_Language" status: "draft" verification_status: "conceptual" canonical_id: "" aliases: ["μžλ°” BufferedWriter"] duplicate_of: "" source_trust_level: "B" confidence_score: 0.88 created_at: 2026-07-04 updated_at: 2026-07-04 review_reason: "" merge_history: [] tags: ["java", "programming", "w3schools", "io", "bufferedwriter", "character-stream"] raw_sources: ["https://www.w3schools.com/java/java_bufferedwriter.asp"] applied_in: [] github_commit: "" --- # [[Java BufferedWriter]] ## 🎯 ν•œ 쀄 톡찰 (One-line insight) `BufferedWriter`'s `newLine()` is the platform-independent way to insert line breaks β€” unlike hardcoding `"\n"` in a string, `newLine()` uses the correct line separator for whatever OS the program runs on, though the source primarily frames it as a convenience method rather than a portability guarantee. [S1] ## 🧠 핡심 κ°œλ… (Core concepts) - **`BufferedWriter`** β€” writes text line/string at a time; must be paired with `FileWriter` (which opens/creates the file). [S1] - **`.newLine()`** β€” inserts a line break, an alternative to embedding `\n` manually. [S1] - **Default overwrite** β€” like FileWriter, replaces existing file content unless append mode is used. [S1] - **Append mode** β€” pass `true` to the underlying `FileWriter` constructor: `new FileWriter("filename.txt", true)`. [S1] ## πŸ“– μ„ΈλΆ€ λ‚΄μš© (Details) - Basic write with newLine(): `try (BufferedWriter bw = new BufferedWriter(new FileWriter("filename.txt"))) { bw.write("First line"); bw.newLine(); bw.write("Second line"); } catch (IOException e) {...}`. [S1] - Append mode: `try (BufferedWriter bw = new BufferedWriter(new FileWriter("filename.txt", true))) { bw.newLine(); bw.write("Appended line"); }`. [S1] - Class comparison: FileWriter (simple/quick), BufferedWriter (faster for large files, easy newLine()), FileOutputStream (binary files). [S1] ## βš–οΈ λͺ¨μˆœ 및 μ—…λ°μ΄νŠΈ (Contradictions & updates) μ†ŒμŠ€μ—μ„œ λͺ¨μˆœλ˜λŠ” μ •λ³΄λŠ” λ°œκ²¬λ˜μ§€ μ•ŠμŒ. ## πŸ› οΈ 적용 사둀 (Applied in summary) ν˜„μž¬ 발견된 μ‹€μ œ 적용 사둀가 μ—†μŠ΅λ‹ˆλ‹€ β€” μ—¬λŸ¬ μ€„μ˜ ν…μŠ€νŠΈλ₯Ό newLine()으둜 κ΅¬λΆ„ν•˜λ©° νŒŒμΌμ— μ“°λŠ” ν‘œμ€€ νŒ¨ν„΄μ΄λ‹€. [S1] ## πŸ’» μ½”λ“œ νŒ¨ν„΄ (Code patterns) Writing multiple lines with newLine() (Java): ```java try (BufferedWriter bw = new BufferedWriter(new FileWriter("filename.txt"))) { bw.write("First line"); bw.newLine(); // add line break bw.write("Second line"); System.out.println("Successfully wrote to the file."); } catch (IOException e) { System.out.println("Error writing file."); } ``` ## βœ… 검증 μƒνƒœ 및 신뒰도 - **μƒνƒœ:** draft - **검증 단계:** conceptual - **좜처 신뒰도:** B (W3Schools β€” widely used educational reference, not a primary standards body) - **μ‹ λ’° 점수:** 0.88 - **쀑볡 검사 κ²°κ³Ό:** μ‹ κ·œ 생성 (New discovery) ## πŸ”— 지식 κ·Έλž˜ν”„ (Knowledge Graph) - **μƒμœ„/루트:** [[Java Tutorial]] - **κ΄€λ ¨ κ°œλ…:** [[Java BufferedReader]], [[Java FileOutputStream]], [[Java Files Write]] - **μ°Έμ‘° λ§₯락:** 버퍼링을 ν†΅ν•œ λΉ λ₯Έ ν…μŠ€νŠΈ μ“°κΈ° β€” Data Structures & Collections μ„Ήμ…˜μœΌλ‘œ 이어짐. ## πŸ“š 좜처 (Sources) - [S1] W3Schools β€” Java BufferedWriter β€” https://www.w3schools.com/java/java_bufferedwriter.asp ## πŸ“ λ³€κ²½ 이λ ₯ (Change history) - 2026-07-04: Initial draft synthesized from the W3Schools "Java BufferedWriter" page (Astra wiki-curation, P-Reinforce v3.1 format).