Java. Io. filenotfoundexception file cannot be found when you use httpurlconnection to download files. The following describes the solution.
First, set the Tomcat code for get data: CONF/server. xml
Encode the requested file name:
Import Java. io. file; import Java.
XML is an alphabetic character, which belongs to ASCII files, why not stream read?) Wait When reading binary files, use a byte stream, such as RAR, EXE, etc. is not a document other than text (picture). The flow at the beginning of the buffered just adds a buffer to improve efficiency in reading and writing. The character stream cannot be output directly, and it needs to be converted into a byte throttling to output (this is really just known)!There are three basic types of nodes in the
The most important 1,io system in the entire Java.io package is 5 classes and one interface. 5 classes refer to aFile, OutputStream, InputStream, Writer, Reader; An interface refers to aSerializable. Mastering the core operations of these IO then there is a preliminary understanding of the IO architecture in Java. java
stream, because the read () method inside the reader stream is read one character at a time, so that each read is a complete Chinese character, which can be displayed correctly. try {in = new FileInputStream ("D:\\java\\myeclipse 10\\workspaces\\annotationtest\\src\\cn\\galc \\test\\FileInputStream. Java ");//in = new FileReader (" D:/java/
After learning the Java NIO and IO APIs, a problem flooded into my mind:
When should I use IO and when to use NIO? In this article, I'll try to clearly parse the differences between Java NiO and Io, their usage scenarios, and how they affect your code design. The main diffe
Java has introduced improvements to input and output from 1.4, and related classes are located in the Java.nio package. There are several features of the new IO:(1) Character Set encoder and decoder(2) Non-blocking IO(3) Memory-mapped file1. Character Set encoders and decodersThe CharSet class represents a different character set, and you can use the Charset.forn
) {E.printstacktrace (); } } }}Results:5 reading of the base data typeImport Java.io.datainputstream;import Java.io.fileinputstream;import java.io.IOException; Public classdatareadtest { Public Static void Main(string[] args) {String Path ="D:\\Program Files (x86) \\ADT\\workspace\\JavaIO\\demoTest.txt"; DataInputStream d =NULL;Try{d =NewDataInputStream (NewFileInputStream (path));//Read basic data types in order of storageSystem. out. println (D.readint ()); System.
is large, memory may not be able to frame such a large array of bytes. Therefore, this method is only suitable for small files. Read Byte Method 3: Read the specified length each time (the most common method)
public static void Main (string[] args) {
try {
Create a byte input stream object
InputStream is=new FileInputStream ("L:\\io.txt");
Specify the size of each read--can be modified based on performance bytes
Byte[]bytes=new Byte[8];
FileFile can create new, delete, rename files and directories, but cannot view file contents.Construction methodpublic File(string pathName);//以path路径创建对象publicFile(StringString child);//以parent为父路径,child为子路径创建File对象Unix under Path delimiter is '/', Windows is ' \ ' or '/'A program that understands the file class//create path plus file in D driveFile d1= New File ("D:/dir1");//Create D1 path if(!d1.exists()) {D1.mkdir ();//If the D1 path does not exist, create the path} file D2 = new
Typical java-16.3 IO usage
Explanation: The InputStream and OutputStream APIs in I/O are easy to use, so they are not skipped for the moment.
This section describes the typical IO usage.
1. A Buffer layer is recommended when I/O is used.
Package com. ray. ch16; import java. io
stream.Conversion flow: Inputstreamreader/outputstreamwriter, converting bytes into charactersBuffered buffer stream:: Bufferedinputstream,bufferedoutputstream,bufferedreader,bufferedwriter, is a processing stream with buffers, bufferingThe main purpose of the district is to avoid dealing with the hard disk every time and improve the efficiency of data access.Object flow: Objectinputstream,objectoutputstream, outputs the encapsulated object directly, rather than converting it into a string.When
Java Io can be divided into two categories: byte stream object and byte stream object. Byte stream objects read data in bytes. The delimiter stream is read in characters. In general, the efficiency of the compaction stream is higher. But why is there a word throttling object?
This is because there are many forms of stream objects. If it is only text data, you can simply use a streaming object. However, most
-Writer.append ("中文版")); + //Close closes the write stream, which writes the contents of the buffer to the file - writer.close (); + //turn off the output stream A fop.close (); at - /** - * read out the file - */ - //Building FileInputStream Objects -FileInputStream FIP =NewFileInputStream (f); in //build the InputStreamReader object with the same encoding as the write -InputStreamReader reader =NewInputStreamReader (FIP, "UTF-8"); to /
(); Pw.close (); 4 , Sequence FlowSequenceinputstream to merge multiple streams. Also known as the merge stream. Common steps to merge multiple stream files:
Creates a vector collection and adds a Stream object into the collection
Creates a enumeration object with the vector's elements () and joins the collection element.
Creating Sequenceinputstream objects, merging stream objects
Create write stream FileOutputStream Object Association write file
Use Sequen
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.
A Free Trial That Lets You Build Big!
Start building with 50+ products and up to 12 months usage for Elastic Compute Service