Posts

Showing posts with the label binary file handling in Java

Reading and Writing Bytes in Java / जावा में बाइट्स पढ़ना और लिखना

Java provides Byte Streams to handle 8-bit data (bytes) for reading and writing files. जावा बाइट स्ट्रीम्स प्रदान करता है, जो 8-बिट डेटा (बाइट्स) को फाइल से पढ़ने और लिखने के लिए प्रयोग होती हैं। Key Points / मुख्य बिंदु:- Use FileInputStream for reading bytes from a file. फाइल से बाइट्स पढ़ने के लिए FileInputStream का उपयोग करें। Use FileOutputStream for writing bytes to a file. फाइल में बाइट्स लिखने के लिए FileOutputStream का उपयोग करें। Suitable for binary files like images, PDFs, and videos. यह बाइनरी फाइल्स जैसे इमेज, PDF और वीडियो के लिए उपयुक्त है। 💻 Example 1: Writing Bytes to a File import java.io.FileOutputStream; import java.io.IOException; public class WriteBytesExample { public static void main(String[] args) { try { FileOutputStream fos = new FileOutputStream("bytefile.txt"); String data = "Hello Byte Stream!"; fos.write(data.getBytes()); fos.close(); Sy...