- Which of the following is true about Java I/O streams?
View Answer
Correct answer: D — All of the above
- What will be printed?
1 import java.io.*; 2 public class Test { 3 public static void main(String[] args) throws Exception { 4 ByteArrayOutputStream out = new ByteArrayOutputStream(); 5 out.write("Eduinq".getBytes()); 6 System.out.println(out.toString()); 7 } 8 } View Answer
Correct answer: A — Eduinq
- Which of the following is true about FileInputStream?
View Answer
Correct answer: D — All of the above
- What will be printed?
1 import java.io.*; 2 public class Test { 3 public static void main(String[] args) throws Exception { 4 File f = new File("Eduinq.txt"); 5 System.out.println(f.exists()); 6 } 7 } View Answer
Correct answer: A — true (if file exists)
- Which of the following is true about BufferedReader?
View Answer
Correct answer: D — All of the above
- What will be printed?
1 import java.io.*; 2 public class Test { 3 public static void main(String[] args) throws Exception { 4 StringReader sr = new StringReader("Eduinq Portal"); 5 BufferedReader br = new BufferedReader(sr); 6 System.out.println(br.readLine()); 7 } 8 } View Answer
Correct answer: A — Eduinq Portal
- Which of the following is true about PrintWriter?
View Answer
Correct answer: D — All of the above
- What will be printed?
1 import java.io.*; 2 public class Test { 3 public static void main(String[] args) throws Exception { 4 CharArrayWriter cw = new CharArrayWriter(); 5 cw.write("Eduinq"); 6 System.out.println(cw.toString()); 7 } 8 } View Answer
Correct answer: A — Eduinq
- Which of the following is true about NIO Channels?
View Answer
Correct answer: D — All of the above
- What will be printed?
1 import java.nio.*; 2 public class Test { 3 public static void main(String[] args) { 4 ByteBuffer buffer = ByteBuffer.allocate(10); 5 buffer.put((byte)65); 6 buffer.flip(); 7 System.out.println((char)buffer.get()); 8 } 9 } View Answer
Correct answer: A — A
- Which of the following is true about FileChannel?
View Answer
Correct answer: D — All of the above
- What will be printed?
1 import java.nio.file.*; 2 public class Test { 3 public static void main(String[] args) throws Exception { 4 Path path = Paths.get("Eduinq.txt"); 5 System.out.println(Files.exists(path)); 6 } 7 } View Answer
Correct answer: A — true (if file exists)
- Which of the following is true about RandomAccessFile?
View Answer
Correct answer: D — All of the above
- What will be printed?
1 import java.io.*; 2 public class Test { 3 public static void main(String[] args) throws Exception { 4 RandomAccessFile raf = new RandomAccessFile("Eduinq.txt","rw"); 5 raf.writeBytes("Eduinq Portal"); 6 raf.seek(0); 7 System.out.println(raf.readLine()); 8 raf.close(); 9 } 10 } View Answer
Correct answer: A — Eduinq Portal
- Which of the following is true about ObjectOutputStream?
View Answer
Correct answer: D — All of the above
- What will be printed?
1 import java.io.*; 2 class Eduinq implements Serializable { 3 String name = "Eduinq Portal"; 4 } 5 public class Test { 6 public static void main(String[] args) throws Exception { 7 ByteArrayOutputStream bos = new ByteArrayOutputStream(); 8 ObjectOutputStream oos = new ObjectOutputStream(bos); 9 oos.writeObject(new Eduinq()); 10 oos.close(); 11 System.out.println("Serialized Eduinq"); 12 } 13 } View Answer
Correct answer: A — Serialized Eduinq
- Which of the following is true about ObjectInputStream?
View Answer
Correct answer: D — All of the above
- What will be printed?
1 import java.io.*; 2 class Eduinq implements Serializable { 3 String name = "Eduinq Portal"; 4 } 5 public class Test { 6 public static void main(String[] args) throws Exception { 7 ByteArrayOutputStream bos = new ByteArrayOutputStream(); 8 ObjectOutputStream oos = new ObjectOutputStream(bos); 9 oos.writeObject(new Eduinq()); 10 oos.close(); 11 ByteArrayInputStream bis = new ByteArrayInputStream(bos.toByteArray()); 12 ObjectInputStream ois = new ObjectInputStream(bis); 13 Eduinq e = (Eduinq)ois.readObject(); 14 System.out.println(e.name); 15 } 16 } View Answer
Correct answer: A — Eduinq Portal
- Which of the following is true about BufferedInputStream?
View Answer
Correct answer: D — All of the above
- What will be printed?
1 import java.io.*; 2 public class Test { 3 public static void main(String[] args) throws Exception { 4 ByteArrayInputStream bis = new ByteArrayInputStream("Eduinq".getBytes()); 5 BufferedInputStream bin = new BufferedInputStream(bis); 6 System.out.println((char)bin.read()); 7 } 8 } View Answer
Correct answer: A — E
- Which of the following is true about NIO Buffers?
View Answer
Correct answer: D — All of the above
- What will be printed?
1 import java.nio.*; 2 public class Test { 3 public static void main(String[] args) { 4 CharBuffer cb = CharBuffer.allocate(5); 5 cb.put('E').put('d').put('u'); 6 cb.flip(); 7 System.out.println(cb.get()); 8 } 9 } View Answer
Correct answer: A — E
- Which of the following is true about Files.readAllLines()?
View Answer
Correct answer: D — All of the above
- What will be printed?
1 import java.nio.file.*; 2 import java.util.*; 3 public class Test { 4 public static void main(String[] args) throws Exception { 5 Path path = Paths.get("Eduinq.txt"); 6 Files.write(path, Arrays.asList("Eduinq Portal")); 7 List<String> lines = Files.readAllLines(path); 8 System.out.println(lines.get(0)); 9 } 10 } View Answer
Correct answer: A — Eduinq Portal
- Which of the following is true about Files.copy()?
View Answer
Correct answer: D — All of the above
- What will be printed?
1 import java.nio.file.*; 2 public class Test { 3 public static void main(String[] args) throws Exception { 4 Path path = Paths.get("Eduinq.txt"); 5 Files.write(path,"Eduinq".getBytes()); 6 byte[] data = Files.readAllBytes(path); 7 System.out.println(new String(data)); 8 } 9 } View Answer
Correct answer: A — Eduinq
- Which of the following is true about FileWriter?
View Answer
Correct answer: D — All of the above
- What will be printed?
1 import java.io.*; 2 public class Test { 3 public static void main(String[] args) throws Exception { 4 FileWriter fw = new FileWriter("Eduinq.txt"); 5 fw.write("Eduinq Portal"); 6 fw.close(); 7 System.out.println("Written"); 8 } 9 } View Answer
Correct answer: A — Written
- Which of the following is true about FileReader?
View Answer
Correct answer: D — All of the above
- What will be printed?
1 import java.io.*; 2 public class Test { 3 public static void main(String[] args) throws Exception { 4 FileWriter fw = new FileWriter("Eduinq.txt"); 5 fw.write("Eduinq"); 6 fw.close(); 7 FileReader fr = new FileReader("Eduinq.txt"); 8 System.out.println((char)fr.read()); 9 fr.close(); 10 } 11 } View Answer
Correct answer: A — E
- Which of the following is true about BufferedWriter?
View Answer
Correct answer: D — All of the above
- What will be printed?
1 import java.io.*; 2 public class Test { 3 public static void main(String[] args) throws Exception { 4 BufferedWriter bw = new BufferedWriter(new FileWriter("Eduinq.txt")); 5 bw.write("Eduinq Portal"); 6 bw.newLine(); 7 bw.write("Next Line"); 8 bw.close(); 9 System.out.println("Written with BufferedWriter"); 10 } 11 } View Answer
Correct answer: A — Written with BufferedWriter
- Which of the following is true about DataInputStream?
View Answer
Correct answer: D — All of the above
- What will be printed?
1 import java.io.*; 2 public class Test { 3 public static void main(String[] args) throws Exception { 4 ByteArrayOutputStream bos = new ByteArrayOutputStream(); 5 DataOutputStream dos = new DataOutputStream(bos); 6 dos.writeInt(100); 7 dos.close(); 8 DataInputStream dis = new DataInputStream(new ByteArrayInputStream(bos.toByteArray())); 9 System.out.println(dis.readInt()); 10 } 11 } View Answer
Correct answer: A — 100
- Which of the following is true about File class?
View Answer
Correct answer: D — All of the above
- What will be printed?
1 import java.io.*; 2 public class Test { 3 public static void main(String[] args) { 4 File f = new File("Eduinq.txt"); 5 System.out.println(f.getName()); 6 } 7 } View Answer
Correct answer: A — Eduinq.txt
- Which of the following is true about Path in NIO?
View Answer
Correct answer: D — All of the above
- What will be printed?
1 import java.nio.file.*; 2 public class Test { 3 public static void main(String[] args) { 4 Path path = Paths.get("Eduinq","Portal","File.txt"); 5 System.out.println(path); 6 } 7 } View Answer
Correct answer: B — Eduinq/Portal/File.txt
- Which of the following is true about Files.createFile()?
View Answer
Correct answer: D — All of the above
- What will be printed?
1 import java.nio.file.*; 2 public class Test { 3 public static void main(String[] args) throws Exception { 4 Path path = Paths.get("EduinqNew.txt"); 5 Files.createFile(path); 6 System.out.println("File Created"); 7 } 8 } View Answer
Correct answer: A — File Created
- Which of the following is true about Files.delete()?
View Answer
Correct answer: D — All of the above
- What will be printed?
1 import java.nio.file.*; 2 public class Test { 3 public static void main(String[] args) throws Exception { 4 Path path = Paths.get("EduinqDelete.txt"); 5 Files.createFile(path); 6 Files.delete(path); 7 System.out.println(Files.exists(path)); 8 } 9 } View Answer
Correct answer: B — false
- Which of the following is true about FileVisitor?
View Answer
Correct answer: D — All of the above
- What will be printed?
1 import java.nio.file.*; 2 import java.io.IOException; 3 public class Test { 4 public static void main(String[] args) throws IOException { 5 Path path = Paths.get("EduinqDir"); 6 Files.createDirectory(path); 7 System.out.println("Directory Created"); 8 } 9 } View Answer
Correct answer: A — Directory Created
- Which of the following is true about Files.walk()?
View Answer
Correct answer: D — All of the above
- What will be printed?
1 import java.nio.file.*; 2 import java.util.stream.*; 3 public class Test { 4 public static void main(String[] args) throws Exception { 5 Path path = Paths.get("EduinqDir"); 6 Files.createDirectories(path); 7 Stream<Path> stream = Files.walk(path,1); 8 stream.forEach(System.out::println); 9 } 10 } View Answer
Correct answer: B — EduinqDir and its contents
- Which of the following is true about Files.lines()?
View Answer
Correct answer: D — All of the above
- What will be printed?
1 import java.nio.file.*; 2 import java.util.stream.*; 3 public class Test { 4 public static void main(String[] args) throws Exception { 5 Path path = Paths.get("Eduinq.txt"); 6 Files.write(path,"Eduinq Portal".getBytes()); 7 Stream<String> lines = Files.lines(path); 8 lines.forEach(System.out::println); 9 } 10 } View Answer
Correct answer: A — Eduinq Portal
- Which of the following is true about FileChannel.transferTo() and transferFrom()?
View Answer
Correct answer: D — All of the above
- What will be printed?
1 import java.nio.*; 2 public class Test { 3 public static void main(String[] args) { 4 ByteBuffer buffer = ByteBuffer.allocate(5); 5 buffer.put((byte)'E').put((byte)'d').put((byte)'u'); 6 buffer.flip(); 7 while(buffer.hasRemaining()) { 8 System.out.print((char)buffer.get()); 9 } 10 } 11 } View Answer
Correct answer: A — Edu