Posts

Showing posts with the label Java Byte Stream

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...

Byte Stream in Java जावा में बाइट स्ट्रीम

Byte Stream in Java is used to read and write 8-bit binary data like files, images, audio, and video. जावा में बाइट स्ट्रीम का उपयोग 8-बिट बाइनरी डेटा को पढ़ने और लिखने के लिए किया जाता है, जैसे फाइल, इमेज, ऑडियो और वीडियो। बाइट स्ट्रीम दो प्रकार की होती हैं:- InputStream (इनपुट स्ट्रीम) OutputStream (आउटपुट स्ट्रीम) 1️⃣ InputStream (इनपुट स्ट्रीम) InputStream is a superclass that reads data from a source like file, device, or socket. InputStream एक सुपरक्लास है जो डेटा को किसी स्त्रोत (फाइल, डिवाइस, या सॉकेट) से पढ़ती है। 🔹 Common Methods of InputStream Method Description (English) विवरण (Hindi) int read()          Reads next byte of data                       अगली बाइट को पढ़ता है int available() Returns number of available bytes उपलब्ध बाइट्स की संख्या लौटाता है void close() Closes the stream स्ट्रीम को बंद करता है 2️⃣ OutputStream (आउटपुट स्ट्रीम) Outp...