Introduction to inputstreamreader and outputstreamwriter. I. inputstreamreader class
Inputstreamreader exchanges byte streams into bytes streams. It is a bridge between byte stream and byte stream. If no character set encoding is specified, the decoding process uses the default character encoding of the platform, for example, GBK.
Constructor:
Inputstreamreader ISR = new inputstreamreader (inputstream in); // constructs an inputstreamreader class for the default Dataset
Inputstreamreade
1 Java program to list all entries in the keystore import java. util. *; import java. io. *; import java. security. *; public class ShowAlias {public static void main (String args []) throws Exception {String pass = "080302"; String name = ". keystore "; FileInputStream in = new FileInputStream (name); KeyStore ks = KeyStore. getInstance ("JKS"); ks. load (in, pass. toCharArray (); Enumeratione = ks. aliase
This article mainly introduces the use of Java InputStream flow.
(1) FileInputStream: Subclass, read the data channel
Use steps:
1. Get target file: New file ()
2. Establish channel: New Fileinputstring ()
3. Read data: Read ()
4. Release resources: Close ()
Some packages that are to be imported by default
import Java.io.File;
Import Java.io.FileInputStream;
Import java.io.IOException;
The public static void main (string[] ar
One: The package that needs to be includedImport java.security.*;Import java.io.*;Import java.util.*;Import java.security.*;Import java.security.cert.*;Import sun.security.x509.*Import Java.security.cert.Certificate;Import Java.security.cert.CertificateFactory;
Second: Read the certificate from the fileWrite the certificate in. KeyStore to the file using Keytool, and then read the certificate information from the fileCertificatefactory cf=certificatefactory.getinstance ("X.509");
The operation of the byte stream and the character stream is basically the same, the difference is only the data unit of the operation is different: the data unit of the byte stream operation is the data unit character of bytes, character stream manipulation.
InputStream and reader are the base classes for all input streams, all of which are two abstract classes and cannot create instances by themselves, but each have an input stream for reading the file: Fi
1 Java program to implement the maintenance of key repository1.1 Java program lists all key library entries
Import java.util.*;
Import java.io.*;
Import java.security.*;
public class showalias{public
static void Main (String args[]) throws exception{
String pass= "080302";
String name= ". KeyStore";
FileInputStream in=new FileInputStream (name);
KeyStore k
of a file. Read and write through streams.Flow concept: A stream is a series of characters flowing, which is a channel for sending information in FIFO mode.The relationship between the input/output stream and the data source:2 Classification of Java streams
The input and output stream is relative to the computer's memory
A byte stream is a 8-bit universal byte stream, which is a 16-bit Unicode character stream
IO system
3 commonly used file reading and writing classesRead
The operation of the byte stream and the character stream is basically the same, the difference is only the data unit of the operation is different: the data unit of the byte stream operation is the data unit character of bytes, character stream manipulation.InputStream and reader are the base classes for all input streams, all of which are two abstract classes and cannot create instances by themselves, but each have an input stream for reading the file: Fil
bytes in the input stream. The returned value is the number of bytes actually ignored. skip some bytes to read(6) public int close (): we must close the opened stream after use.Main subclass: 1) FileInputStream uses a file as InputStream to read the file.2) ByteArrayInputStream: uses a buffer in the memory as an InputStream.3) StringBufferInputStream: Use a String object as InputStream.4) PipedInputStream: implements the pipe concept and is mainly us
FilesYou can use FileInputStream or filereader to read into a file based on binary, which is based on text. They do not need to read the entire file, but can read bytes, or characters sequentially, in the order in which they are stored.Using FileOutputStream or FileWriter, data can be written out to a file and stored in the order in which the data is written.Randomaccessfile can jump into a file, read data, or write data to a file. Random Access does
IO exception handling when used
After use, release resources
20.02_io Stream (FileInputStream)
Read () reads one byte at a time
publicstaticvoidmain(String[] args) throws IOException { new FileInputStream("xxx.txt"); //创建流对象 int b; while((b=fis.read())!=-1){ //从硬盘上读取一个字节,读到文件结尾,返回-1 System.out.printl
写入此输出流 void write(byte[] b, int off, int len) // 将指定的字节写入此输出流 abstract void write(int b) // 关闭此输出流并释放与此流有关的所有系统资源 void close() // 刷新此输出流并强制写出所有缓冲的输出字节 void flush()(2). Byte file operation flow 1). fileinputstreamFileInputStream: A byte file input stream that obtains input bytes from a file in the file system for reading raw byte streams such as data. 构造方法: // 通过打开一个到实际文件的连接来创建一个FileInputStream,该文件通过文件系统中的File对象file指定
position of the BUF
b, outputstream output flow This operation method
Out.write (INTB); writes a byte to stream, writes a low 8 bit
out.write (byte[]buf) of B, and writes a BUF byte array to the stream
Out.write (byte[]buf,int Start,int size); The byte array buf writes the byte of size length from the start position to the stream.
C, FileInputStream Concrete implementation of the file read the file
Note:1> A single byte of reading is not an arra
the value of append is set to true, content is appended to the end of the file.
OutputStream out=new FileOutputStream(file,true);Byte input stream: inputstream
Since the program can write content to the file, it can read the content from the file through inputstream. First, let's look at the definition of the inputstream class:
public abstract class InputStream extends Object implements Closeable
Like outputstream, inputstream itself is also an abstract class and must rely on its subclass. If i
Java byte stream used in Android, java byte stream android
Reprinted please indicate the source: http://www.cnblogs.com/cnwutianhao/p/6611252.html
Introduction: project development sometimes uses the process of uploading files to the server and then retrieving data from the server to display the data locally. Alternatively, you can enter a piece of text to display the text. IO streams are used in this process.
IO streams are classified into two types: Reader/Writer and InputStream/OutputStream)
the contents of: Used to try the first demo of InputStream. */ Try { //If you cannot find such a file in this path, it will be reported that the file did not find the exception, so use FileNotFoundException packageFileInputStream FileInputStream =NewFileInputStream (NewFile ("F:\\tryfile\\a.txt")); byte[] contents =New byte[1024]; Fileinputstream.read (contents);//There will be a read and write exception, and then from the file stre
. Therefore, it is necessary to merge streams. The middle and dark colors are the node streams, and the light colors are the processing streams. Here, the void write (String string) method writes the characters in a String to the output stream. The implementation process is to call java. lang. the toCharArray () method of String converts the String into a character array and writes it to the output stream. Void write (String string, int offset, int length) throws IOException starts from the offs
, you can set another pipe outside this pipe, and the flow over the other pipe is called the flow of processing. Why do we need to process the flow? This is with the flow of impurities, you have to filter it, you can set a layer of pipe to filter these impurities.3.1. Node stream type A node stream is a pipe that plugs directly into the data source, reads data directly from the data source, or writes data directly to the data source. A typical node stream is a file stream: A file's byte input s
not satisfied with the original flow, you can set another pipe outside this pipe, and the flow over the other pipe is called the flow of processing. Why do we need to process the flow? This is with the flow of impurities, you have to filter it, you can set a layer of pipe to filter these impurities.3.1. Node stream type A node stream is a pipe that plugs directly into the data source, reads data directly from the data source, or writes data directly to the data source. A typical node stream is
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.