TitleImportJava.io.BufferedInputStream;ImportJava.io.BufferedOutputStream;ImportJava.io.FileInputStream;ImportJava.io.FileOutputStream;ImportJava.io.FileReader;ImportJava.io.FileWriter;ImportJava.io.IOException;ImportJava.io.InputStream;ImportJava.io.OutputStream;ImportJava.io.Reader;ImportJava.io.Writer;/ * * Filereader/filewriter class * file character input/output stream */ Public class Test03 { Public Static void Main(string[] args)throwsIOEx
* Copy of text files can be achieved using FileReader and FileWriter.* For non-text files (video files, audio files, pictures), only the byte stream can be used!1 @Test2 Public voidTestfilereader () {3FileReader FR =NULL;4 Try {5File File =NewFile ("Dbcp.txt");6FR =Newfilereader (file);7 Char[] C =New Char[24];8 intLen;9 while(len = Fr.read (c))! =-1){TenString str =NewString (c, 0, Len); One System.ou
The code is as follows
Copy Code
More about the content reference
Ps://developer.mozilla.org/en/dom/filereader ">https://developer.mozilla.org/en/dom/filereader
Using Ajax is not directly uploaded files, is generally a new iframe in it to complete the form submission process to achieve the effect of asynchronous upload files.Doing so can achieve better browser compatibility, but the amount of code will be relatively large, even with the use of file upload plug-ins, such as Plupload.
How can you be flexible enough to treat a file as a normal form parameter like a normal AJAX submission form data?
Flash, the use of JavaScript
4 Main methods:Abort (): Interrupt read.Readasbinarystring (): reads the file as a binary code.Readasdataurl (): reads the file as Dataurl.Readastext (): reads the file as text.Event:Onabort: When interruptedOnError: Error whenOnLoad: Read successOnloadend: Read complete regardless of failure or successOnloadstart: Read startOnProgress: in Read2 Properties:Result: The value is only available after the read succeeds, and no is empty.ReadyState:0: for reading data1: Reading2: CompleteHTML5
Brief introduction
With the FileReader object, a Web application can asynchronously read the contents of a file (or raw data buffer) stored on a user's computer, and you can use a file object or a Blob object to specify the files or data that you want to work with. Where the file object can be from a user in a
More than one page, upload multiple pictures demo code
The above is the entire content of this article, I hope to learn JavaSc
sets the width of the screen at the beginning and then reads the data from each channel into the row.Row is a data buffering mechanism.There are a few other ways:The following methods are optional and do not have to be defined for each one. They provide some additional features and information to the reader class.void Dd::image::reader::p refetchmetadata ()This method can be used to get metadata (metadata) for a particular frame.Const metadata::bundle Dd::image::reader::fetchmetadata (const cha
. listfiles (); // retrieves an array of file objects representing all files in the directory
Out. println ("
For (INT I = 0; I
If (list
Out. println (list
}
}
Out. println ("
For (INT I = 0; I
If (list
Out. println (list
}
}
%>
Determines whether the file is blank.
>
String Path = request. getrealpath ("/");
Out. println (PATH );
Filereader Fr = new filereader (path + "\ atend.txt"); // cr
buffer, in general, every read request made by reader causes the corresponding read request to the underlying character or byte stream, and if there is no buffer, each call to read () or readLine () causes the bytes to be read from the file and converts it to characters and returns, which is extremely inefficient.You can use BufferedReader to specify the size of the buffer, or you can use the default size. In most cases, the default value is large enough.Therefore, it is recommended to use Buff
(); // retrieves an array of File objects representing all files in the directoryOut. println ("For (int I = 0; I If (list Out. println (list }}Out. println ("For (int I = 0; I If (list Out. println (list }}%> Determines whether the file is blank. The code is as follows:Copy code String path = request. getRealPath ("/");Out. println (path );FileReader fr = new FileReader (path + &q
.*;Main (){FileWriter Fw=null; try{fw=new FileWriter ("Demo.txt"); Fw.write ("ABCDE");} catch (IOException e) {System.out.println (e.tostring ()); }
finally{
try{
if (fw!=null) fw.close ();
catch (IOException e) {System.out.println (e.tostring ()); } } }The continuation of the file, starting from its constructorFileWriter fw=new FileWriter ("Demo.txt", true);Fw.write ("ABCDE");2, read the text file FileReader(1) Read a single character at a timeMain (
(PATH );Filereader Fr = new filereader (path + "// atend.txt"); // create a filereader object and instantiate it as fr// Use the read () method for the object generated by the filereader class to read the next character from the delimiter stream.If (Fr. Read () =-1) // determines whether the object has been read to th
virtual directories in JSP Obtain the disk path corresponding to the virtual directory
File Attribute acquisitionString Path = request. getrealpath ("/");File F = new file (path, "readdata.txt ");If (F. exists ()){%>The attributes of File length: The last modification date of the file is: } Else {F. createnewfile (); // create a file named readata.txt in the current directory.%>The attributes of File length: The last modification date of the file is: }%>
How to retrieve files in a directory St
conceptsPreviously, we needed to understand some concepts.Java uses 16-bit Unicode to represent strings and characters. We can specify the encoding of the string to write when writing a stream of characters.Here bloggers stick out the character stream class diagram structure, convenient for ape friends to read:In the file operation we mainly use FileReader and FileWriter or BufferedReader and BufferedWriter.From the class structure diagram:FileReader
selects by input[type= the "file" elementBlob interface: Used to represent a piece of binary data, and allows us to "cut" its data in bytes by JSFile interface: Used to transport a document, is inherited from the Blob interface, and on this basis added such as file name, MIME type and other featuresFileReader interface: Provides methods and events for reading filesFileList interface
#FileList [index]//Get index file
Blob interface
#Blob. Size//read-only attribute, number
.
Java uses 16-bit Unicode to represent strings and characters. You can specify the encoding of the Written string when writing data to the upstream stream.
Here, the blogger posts the structure of the livestream graph to facilitate reading by yuanyou:
During file operations, we mainly use FileReader, FileWriter, BufferedReader, and BufferedWriter.
Signature + 0o7o8L3A + signature + PC9wPg0KPHA + signature/Signature + PC9wPg0KPHA + signature + w
to be read from the file and converted to characters, which is extremely inefficient.You can use BufferedReader to specify the size of the buffer, or you can use the default size. In most cases, the default value is large enough.Therefore, it is recommended to use BufferedReader to wrap all of their read () operations with potentially expensive Reader (such as FileReader and InputStreamReader). For exampleBufferedReader in= new BufferedReader (New
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.