Files and I/O
- What is the output of this program?
import java.io.*;
public class Chararrayinput_Example
{
public static void main(String[] args)
{
String object = "InterviewMania";
int len = object.length();
char ch[] = new char[len];
object.getChars(0, len, ch, 0);
CharArrayReader chararray = new CharArrayReader(ch);
CharArrayReader chararray0 = new CharArrayReader(ch, 0, 9);
int i;
try
{
while((i = chararray0.read()) != -1)
{
System.out.print((char)i);
}
}
catch (IOException e)
{
e.printStackTrace();
}
}
}
-
View Hint View Answer Discuss in Forum
NA
Correct Option: A
Interview
- What is the output of this program?
import java.io.*;
public class Chararrayinput_Example
{
public static void main(String[] args)
{
String object = "InterviewMania";
int len = object.length();
char array[] = new char[len];
object.getChars(0, len, array, 0);
CharArrayReader chararray = new CharArrayReader(array);
CharArrayReader chararray0 = new CharArrayReader(array, 1, 4);
int K;
int L;
try
{
while((K = chararray.read()) == (L = chararray0.read()))
{
System.out.print((char)K);
}
}
catch (IOException e)
{
e.printStackTrace();
}
}
}
-
View Hint View Answer Discuss in Forum
NA
Correct Option: E
No output is printed. CharArrayReader object input1 contains string “InterviewMania” whereas object chararray contains string “nter”, when while((K=chararray.read())==(L=chararray.read())) is executed the starting character of each object is compared since they are unequal control comes out of loop and nothing is printed on the screen.
- Which method is used to create a directory with fileattributes?
-
View Hint View Answer Discuss in Forum
NA
Correct Option: D
New directory can be created using Files.createDirectory(path, fileAttribute).
- What is the output of this program?
public class Main
{
public static void main(String args[])
{
StringBuffer strbuf = new StringBuffer("Interview");
StringBuffer strbuf0 = new StringBuffer(" Mania");
strbuf.append(strbuf0);
System.out.println(strbuf);
}
}
-
View Hint View Answer Discuss in Forum
NA
Correct Option: C
append() method of class StringBuffer is used to concatenate the string representation to the end of invoking string.
- How can we delete all files in a directory?
-
View Hint View Answer Discuss in Forum
NA
Correct Option: B
The delete(Path) method deletes the file or throws an exception if the deletion fails. If file does not exist a NoSuchFileException is thrown.