FileInputStream
"Font-family:verdana;">import java.io.File;
Import Java.io.FileInputStream;
Import Java.io.InputStream;
Public class Testfileinputstream {
public static void Main (string[] args) throws Exception { //exception thrown, not processed
//1th step: Use the file class to find a document
File F = new file ("C:" + File.separator + "test.txt"); Declaring a File object
//2nd step: Instantiating a parent class object
Packageitcast_02;Importjava.util.Arrays;/** How to recognize the conversion of a byte to Chinese in the computer? * The storage of Chinese in the computer is two bytes: * First byte: must be negative * Second byte: May be negative (common), may also be positive, no effect * **/ Public classFileInputStreamDemo2 { Public Static voidMain (string[] args) {String s= "ABCDE"; //[98, 101] byte[] bye =s.getbytes (); System.out.println (arrays.tostring (bye)); System.out.println ("---------
String Realpath = Request.getrealpath ("web-inf/classes/com/properties/devicetype.properties");The above is the most correct way to get the path, so the properties can be placed under a COM package, or in the SRC directory.Properties props =NewProperties (); ArrayList Al=NewArrayList (); Try{InputStream in=NewBufferedinputstream (NewFileInputStream (Realpath)); Props.load (in); Enumeration en=Props.propertynames (); while(En.hasmoreelements ()) {String key=(String) en.nextelement
Close to do a very simple function, to two return values, I intend to have a class encapsulated a return, then the leader asked to use StringBuilder return, do not stringbuffer, because the local variable StringBuffer finally to compile to StringBuilder Because StringBuilder does not have any synchronization.
Ask everybody's opinion, the wind South said InputStream int read (byte[] b) reads a certain number of bytes from the input stream and stores it in buffer array B, which is similar, it see
A simple web server example and a simple web server example
A simple web Container example has simple functions and can only access static resources. It is of some significance for beginners. There are three main types:
1. server: The main function is to enable socketServer, block server, receive socket access, parse request, create request, and respond.
Public c
Python decorator use example and actual application example, python example
Test 1
Deco is running, but myfunc is not running
Copy codeThe Code is as follows:Def deco (func ):Print 'before func'Return func
Def myfunc ():Print 'myfunc () called'Myfunc = deco (myfunc)
Test 2
Call myfunc in the required deco to executeCopy codeThe Code is as follows:Def deco (func
/*======================================================================
A Globalmem Driver As an example of char device drivers
There are two same globalmems in this driver
This example was to introduce the function of File->private_data
The initial developer of the original code is Baohua Song
======================================================================*/
#include #include #include #include #in
Notebook class:Package Cn.fanse;public class Notebook {public void run () {System.out.println (' book Run ');} public void Useusb (USB usb) {Usb.open (); Usb.close ();} }USB Interface:Package Cn.fanse;public interface USB {public void open (); public void close ();USB Interface for Mouse:Package Cn.fanse;public class Mousebyusb implements usb{@Overridepublic Void Open () {System.out.println ("mouse Run");} @Overridepublic void Close () {System.out.println ("mouse Close");} }Keyboard for U
data streams that file as data output, and to write to files. Its construction methods are:
FileOutputStream (File f);
FileOutputStream (File F, Boolean B);
FileOutputStream (String f);
Its main method is to overwrite the parent class: write (int b), write (Byte[]b), write (Byte[]b,int off,int len), close (), flush ().
5, DataInputStream and DataOutputStream class
The objects created by the Dateinputstream and DataOutputStream classes are called data input streams and data output streams,
We have already seen that JDBC DriverManager can is used to get relational database connections. But if it comes to actual programming, we want more than just connections.Most of the times we is looking for loose coupling for connectivity so, we can switch databases easily, connection POOling for transaction management and distributed systems support. JDBC DataSource is the preferred approach if you be looking for all of these features in your application. JDBC DataSource interface is present in
The serialization mechanism in Java is implemented in two ways:One is to implement the Serializable interfaceThe other is to implement the Externalizable interfaceDifference:Implementing the Serializable interface1 The system automatically stores the necessary information2 Java built-in support, easy to implement, just implement the interface, without any code support3 performance is slightly worseImplementing the Externalizable Interface1 Programmers decide what information to store2 provides o
info to verify whether the information is signed by him/her.Read Public KeyJava. io. ObjectInputStream in = new java. io. ObjectInputStream (new java. io. FileInputStream ("mypubkey. dat "));PublicKey pubkey = (PublicKey) in. readObject ();In. close ();
Read signature and informationIn = new java. io. ObjectInputStream (new java. io. FileInputStream ("myinfo. dat "));String info = (String) in. readObject (
Java Get File size
Today, when writing code to achieve the function of getting file size, there are two implementations, one is using the length () method of file, and the other is using the FileInputStream available () method, when InputStream does not perform a read operation , the size of the available () should be equal to the file size. However, when working with large files, the latter can cause problems. Let's take a look at:
In the
that they are the same object, but they are different from the object addresses of other streams. That is to say, as long as the object is serialized to a single class, we can restore the same object network as we write, and as long as the same class, the object is the same.
7. serialization of static variables
If you add static before the age variable in the above Code, the output is still
Name = SheepMuAge = 24
But let's look at the example below:
The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion;
products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the
content of the page makes you feel confusing, please write us an email, we will handle the problem
within 5 days after receiving your email.
If you find any instances of plagiarism from the community, please send an email to:
info-contact@alibabacloud.com
and provide relevant evidence. A staff member will contact you within 5 working days.