You are on page 1of 2

} import java.io.

FileInputStream;
import java.io.InputStream;
public class Main { public static void main(String args[]) {
byte[] array = new byte[100];
try {
InputStream input = new FileInputStream("output.txt");
System.out.println("Available bytes in the file: " + input.available());
// Read byte from the input stream
input.read(array);
System.out.println("Data read from the file: ");
// Convert byte array into string
String data = new String(array);
System.out.println(data);
// Close the input stream
input.close();
}
catch (Exception e) {
e.getStackTrace();
}
}
}

Output:

Available bytes in file:51


Data read from the file
This is the line of the text inside the file. 123 sample

Debugging skills

Program#1.

Output Point out the error(s) and how they can be fixed
Output: Enter a string: 66 Line 1 add letter o after the letter i
Data is written to the file Line 2 add letter i before the letter o
(output.txt) Line 5 add letter I to the word static
Line 7 add letter t to the word print
Line 9 add the word File before the word
OutputStream
Line 15 add letter e to the word exception

You might also like