Professional Documents
Culture Documents
import java.io.FileOutputStream;
import java.io.OutputStream;
Output:
Data is written to a file.
} 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:
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
Program#2.
Output Point out the error(s) and how they can be fixed
Enter (1) ouput.txt file (2) data.txt file: 55 Data Line 3 remove the sign # and insert *
not found Line 7 fixed the letter s in the word scanner and
make it capitalize S
Line 25 insert another = before the 2
Line 27 add the word File to the word
InputStream
Line 31 add letter r to the word array