Cho biết số byte mà đoạn chương trình sau ghi ra tập tin temp. txt
import java.io. * ;
public class TestIOApp {
public static void main(String args[]) throws IOException {
FileOutputStream outStream = new FileOutputStream("temp.txt");
String s = "test";
for (int i = 0; i
outStream.write(s.charAt(i));
outStream.close();
}
}
import java.io. * ;
public class TestIOApp {
public static void main(String args[]) throws IOException {
FileOutputStream outStream = new FileOutputStream("temp.txt");
String s = "test";
for (int i = 0; i
outStream.write(s.charAt(i));
outStream.close();
}
}
public class TestIOApp {
public static void main(String args[]) throws IOException {
FileOutputStream outStream = new FileOutputStream("temp.txt");
String s = "test";
for (int i = 0; i
outStream.write(s.charAt(i));
outStream.close();
}
}
Trả lời:
Đáp án đúng: B
Đoạn chương trình Java trên thực hiện việc ghi chuỗi "test" vào file "temp.txt". Vòng lặp `for` lặp qua từng ký tự của chuỗi `s` (tức là "test"). Hàm `outStream.write(s.charAt(i))` ghi từng ký tự này vào file. Chuỗi "test" có 4 ký tự, do đó, chương trình sẽ ghi 4 bytes vào file.





