Untitled
unknown
plain_text
a month ago
1.1 kB
6
Indexable
package StreamPackage;
import java.io.FileInputStream;
import java.io.FileOutputStream;
import java.io.IOException;
public class ByteStreamOperation {
public static void main(String[] args) {
String path = "C:\\Users\\Student\\OneDrive\\Desktop\\STream\\Input.txt";
try {
// WRITING INTO FILE
FileOutputStream fos = new FileOutputStream(path);
String message = "Hello Java Byte Stream";
fos.write(message.getBytes());
fos.close();
System.out.println("Data written successfully.");
// READING FROM FILE
FileInputStream fis = new FileInputStream(path);
int data;
System.out.println("Reading data from file:");
while ((data = fis.read()) != -1) {
System.out.print((char) data);
}
fis.close();
} catch (IOException e) {
System.out.println("Error: " + e.getMessage());
}
}
}Editor is loading...
Leave a Comment