What are the common IO interview questions in Java?
Editor to share with you what Java common IO interview questions are, I believe most people do not know much about it, so share this article for your reference, I hope you can learn a lot after reading this article, let's go to know it!
1: what is flow?
String decomposition = OutStream= > write () method is written to the file
2: describe the basic interface and class structure of the Imax O stream
InputStream
OutputStream
3: code example: how to use URL streams for input and output
Try {imageSource = new URL ("http://mysite.com/~info");} catch (MalformedURLException e) {})
4: what is Unicode?
It's a way of encoding characters.
5: code example: how to use Reader and Writer for input and output
InputStreamReader ir = new InputStreamReader (System.in); OutStreamReader or = new OutStreamReader (System.in)
6: what is serializable? How to achieve serializability?
Indicates that a data can be streamed out.
Implement the java.io.Serializable interface
7: code example: how to read and write object streams
/ / read try {String str = "123"; FileOutputStream f = new FileOutputStream (" test.txt "); ObjectOutputStream s = new ObjectOutputStream (f); s.writeObject (str); f.close ();} catch (Exception e) {e.printStackTrace ();} / write try {FileInputStream f = new FileInputStream (" test.txt "); ObjectInputStream s = new ObjectInputStream (f); str = (String) s.readObject (); f.close ();} catch (Exception e) {e.printStackTrace ();}
8: briefly describe the basic functions of the File class
Management of processing files and obtaining file information, files or folders
You can do anything except read and write the contents of the file.
9: code example: how to use random file read-write classes to read and write file contents
RW represents the readable reads and writes of a file: try {RandomAccessFile f = new RandomAccessFile ("test.txt", "rw"); long len = 0L; long allLen = f.length (); int I = 0; while (len)
< allLen) { String s = f.readLine(); if (i >0) {col.add (s);} iPremium; / / Vernier len = f.getFilePointer ();}} catch (Exception err) {err.printStackTrace ();} write: try {RandomAccessFile f = new RandomAccessFile ("test.txt", "rw"); StringBuffer buffer = new StringBuffer ("\ n"); Iterator it = col.iterator () While (it.hasNext ()) {buffer.append (it.next () + "\ n");} f.writeUTF (buffer.toString ());} catch (Exception err) {err.printStackTrace ();}
10: code example: how to use the basic interface of a stream to read and write the contents of a file
Try {DataInputStream in = new DataInputStream (new BufferedInputStream (new FileInputStream ("Test.java")); while ((currentLine = in.readLine ())! = null) {System.out.println (currentLine);}} catch (IOException e) {System.err.println ("Error:" + e);} above are all the contents of the article "what are the Common IO interview questions in Java?" Thank you for reading! I believe we all have a certain understanding, hope to share the content to help you, if you want to learn more knowledge, welcome to follow the industry information channel!