java-based Notes (4)

Binary arithmetic:

& Applications: clear, get the specified number of bits;

| Applications: the specified location to take 1;

^ Application: inversion, retained the original value; bian exchange two variables: A = A ^ B, B = A ^ B, A = A ^ B; (XOR principle is itself se = 0, = 0 XOR itself itself)

<< / >>: left / right, attention is negative: negative is inverted by the absolute value and plus complement representation into a; negative representation obtained which was then left shifting operation, the Save the repeated inverted, and then to take the opposite number, so the left / right itself will not change the number of positive and negative, no symbol left shift is possible to change the positive or negative;

<<< / >>>: Unsigned left / right

 

 

java binary conversion:

Decimal to other binary: Integer.toxxxxx (xxx); to convert a few hex decimal xxx;

Another binary to binary: Integer.parseInt ( "xxx", yyy); yyy the hexadecimal value of the number is converted to decimal xxx;

 

 

Binary application, when we cross-platform and the underlying platform is not the same kind of written language when it can be expressed by converting the data communication bytes;

 

 

-Byte data types into a big endian and little-endian,

Small end rule low byte address into low end, i.e. the value of the memory starting address, high address high byte into sections;
big-endian byte rule into the high address end of the low, low and high byte address segment into ;

 

 

IO input and output

gbk coding, text occupies two bytes, one byte letters; (default program)

utf-8 encoded, Chinese occupy three bytes, one byte letters;

encoding utf-16be, Chinese letters, and two bytes are occupied;

Thus, if the wanted byte array into a string or a number, corresponding to only apply transcoding to convert the signal correctly without distortion;

We usually text files created on a computer, using the default encoding ansi, so when we save with additional coding, then open will be garbled; (Note: This does not mean only know ansi text file encoding tool, it itself is know a lot of coding, such as you use utf-8 file has been written to open a text file, it is not garbled, but will default encoding ansi when a new file is created with it)

 

 

java.io.File; File class only show files (directory) information (name, size)

File file = new File ( "E: \\ javaio"); javaio in the E disk access; common methods:

file.exists (): whether the file exists;

file.mkdir () / file.mkdirs (): If the file does not exist, create a file; / multi-level directory

file.delete (); delete files;

file.isDirectory (); determine whether the file is a directory;

file.isFile (); whether the file is a file

 file.getAbsolutePath (); finding files absolute path;

file.getName (); name to view the file;

file.getParent (); parent directory to view files;

 

 

 

File type filtering, traverse

File.List for (); returns a string array, the name of the child, does not contain the contents of the subdirectory;

If you want to traverse directories under a subdirectory, we can not return an array of strings, so can not do recursive; and to return a File object;

File [] files = file.listFiles (); array of objects returned directly subdirectory files;

By traversing files, and determines whether the files directory, the recirculation case directory traversal, the case file print output, so to return to a directory of all child subdirectories of the document;

 

 

RandomAccessFile the java class provide access to the contents of the file, read and write; support random access, i.e., anywhere access files;

RW has the file open mode (read-write), r (read-only) Example:

RandomAccessFile raf = new RandomAccessFile(file,“rw”);

Open the file pointer at the beginning of the beginning;

commonly used ways:

raf.write (int); write only one byte (after 8); also a pointer to the next position;

int b = raf.read (); a byte read-only

raf.getFilePointer (); return position pointer is located;

raf.seek (int); into the position indicated by the pointer;

After the completion of file reading and writing to be closed;

 

 

Byte stream

InputStream: applications to read data abstract manner;

OutputStream: abstract way to write the application data;

EOF = End to end reading enrolled -1

InputStream abstract class provide the method:

int b = In.read (): read a byte int filled into the bottom eight bits;

In.read (byte [] buf); read data in buf byte array filled

Inread (byte [] buf, int start, int size); read data in buf byte array is filled, starting from the start position of the byte array buf, data storage size length

When reading data, the number of bytes in the array we will read out, but since int is 32 bits, we have written into byte array substrate int class only 8 bits, 24 through high & 0xff cleared;

OutputStream abstract class provide the method:

Out.write (int b); a byte written to the stream, b of the bottom eight;

Out.write (byte [] buf) The buf byte array to the stream;

Out.write (byte [] buf, int start, int size); buf byte array, starting from start, the byte size written to the stream length;

 

FileInputStream: InputStream subclass, embodied on a read file data then

 

Note that FileOutputStream where the parameter can be (filename, [ture]); if added true, it means that the additional contents of the file, if there is no argument true, the presence of the file, delete the file content and add new content, such as not files, create files and add new content;

 

 

 

DataOutputStream / DataInputStream: spreading the stream;

Class parameter is passed outputStream / InputStream class provides methods of different types can be passed directly, without first pass after passing in the array of bytes, such as:

outputStream class

 

InputStream class

 

 

 

 

BufferedInputStream / BufferedOutputStream categories: these two classes provide streams with the operation of the IO buffer;

 Efficiency in the reading and writing of files, read and write buffers with batch is more efficient;

 

 

Jifuryu:

Text: java text is 16-bit unsigned integer, encoded unicode characters (two-byte code)

File is a byte, byte, byte data sequence;

Text file: a text (char) according to some coding scheme into a byte sequence memory;

Character stream (Reader class / Writer class)

InputStreamReader categories: complete byte stream analysis of char stream, press code resolution

OutputStreamWriter categories: complete byte stream flowing char, press code resolution

 

 

 

 FileReader / FileWriter: an object that can be used to directly create character streams, the disadvantage is to create a function of the class does not provide a method to specify the encoding format, and therefore to specify the encoding format, or the need to use the above-described class InputStreamReader;

 

 

 

 

Filter character stream:

BufferedReader -------> readline: a read line;

BufferedWriter / PrintWriter ---------> writing a single line;

 

 Note that these two methods are not recognized classes wrap, so when read with the println, written with time after the write, later to be called newLine () method of line feed operation;

 PrintWriter class will be relatively simple in creation, it can be directly added to the file name to create it:

 

 Write operation using a println () can be written directly and line:

 

 

 

 Serialization and deserialization objects: Object converted into a byte sequence, otherwise called object deserialization;

Serialization stream (the ObjectOutputStream), filtered byte streams commonly used methods: writeObject ();

Deserialization stream (ObjectInputStream), commonly used methods: readObject ();

Serial interfaces (the Serializable)

Objects must implement the interface, then serialization can be serialized;

 

 Deserialization:

 

 

If the elements of an object with a transient modification, it will not be jvm default serialization, but can complete their sequence of this element;

Polar sequence relationship parent class:

When the subclass is deserialized operation, if the parent class does not implement the serialization interface, then the parent class constructor is invoked;

 

 

Guess you like

Origin www.cnblogs.com/lzj-learn/p/11837263.html