Transferred from: Http://hi.baidu.com/danghj/item/0ef2e2c4ab95af7489ad9e39Resources:L "Core Java" chapter 12L How to manipulate text files using Java http://java.ccidnet.com/art/3737/20041108/523627_1.htmlWhat kind of FileReader is L? What's the difference with FileInputStream? Http://book.hackbase.com/ask2/ask107572.htmSelf-collation and understanding:Introduct
Use and difference of fileinputstream, filereader, inputstreamreader file, fileinputstream, filereader, inputstreamreader, and bufferedreaderReferences:Chapter 12 of core JavaDetailed description of http://java.ccidnet.com/art/3737/20041108/523627_1.html using Java to operate text filesWhat is filereader class? What is the difference with
");e.printStackTrace();}System.out.println ();// 例2 – Java中使用FileReader 读取文件数据try (FileReader reader = new FileReader("c:/data.txt")) {int character = reader.read();while (character != -1) {System.out.print (integer.tohexstring (character));System.out.print((char) character);character = reader.read();}} catch (IOException io) {System.out.println("Failed to read character data from File");io.printStackTrace();}}}
Save As UTF-8 output:
InputStream objects created with the FileInputStream class can be used to read content from a file. The two commonly used constructors are as follows: FileInputStream (String FilePath) FileInputStream (File fileobj) Both constructors will throw filenotfoundexception exceptions. Where FilePath is the full pathname of the file, and Fileobj is the file object that
, FileInputStream needs to invoke the underlying language implementation through native methods.Here's a simple example: Public classfileintest { Public Static void Main(string[] args) throws FileNotFoundException {InputStream is=NewFileInputStream ("F:/shiro-config.ini");intITry{i = is. read (); while(I! =-1) {System. out. println (Char) (i); i = is. read (); } is. Close (); }Catch(IOException E1) {//TODO
FileInputStream by opening a connection to the actual file, which is specified by the pathname name in the file system.Reader|--bufferedreader|___inputstreamreader|__filereaderBufferedReader: Reads text from the character input stream, buffering individual characters, enabling efficient reading of characters, arrays, and rows. Construction Method SummaryBufferedReader (Reader in)Creates a buffered character input stream that uses the default size inp
to specify the encoding methodclass, while the parameters and FileInputStream of the FileReader constructorAs a file object or a string representing path, you can see that the filereader is used when you want to read a document according to the files object or string;I think the role of FileReader sub-category is the small division of labor.Two relations and differences(1) characters and bytes:The FileInputStream
what is InputStream and OutputStream.
InputStream and OutputStream are abstract classes that are the parent class for all byte input and output streams. Here, we first need to clarify two concepts: InputStream (Input stream): the input stream is used to read data. --> > > Read outputstream (Output stream): Output stream is used to write data. --> > > Write file input stream--fileinputstream
FileInputStream
This chapter describes FileInputStream and FileOutputStream
Introduction to FileInputStream and FileOutputStream
FileInputStream is the file input stream, which inherits from InputStream.
Typically, we use FileInputStream to get input bytes from a file.
FileOutputStream is the file output stream, which inherits fro
() returns the unique FileChannel object associated with this file output stream. FileDescriptor GETFD () returns the file descriptor associated with this stream. Here is an example of copying an EXE executable file via FileInputStream and FileOutputStream.ImportJava.io.File;ImportJava.io.FileInputStream;Importjava.io.FileNotFoundException;ImportJava.io.FileOutputStream;Importjava.io.IOException;ImportJava
connection to the file and ensures that the Close method of this stream is called when the file output stream is no longer referenced.
FileChannel
Getchannel () returns the unique FileChannel object associated with this file output stream.
FileDescriptor
GETFD () returns the file descriptor associated with this stream.
void
Write (byte[] b) writes B.length bytes from a specified byte array to this file output stream.
void
);//write the string into the file}Catch(IOException e) {System. out. println ("Error"+E); } }}Example: Copying a file to another fileImportJava.io.File;ImportJava.io.IOException;ImportJava.io.FileOutputStream;ImportJava.io.FileInputStream; Public class test{ Public Static void Main(String args[])throwsIOException {Try{File FromFile =NewFile ("A.txt"); File ToFile =NewFile ("B.txt"); FileInputStream
Example 1 is an example of using fileinputstream and fileoutputstream. the program can copy the file. It will first read data from the source file to a byte array, and then write data from the byte array to the target file. example 1: filestreamdemo. javaimport Java. io. *;
provide byte stream reads in bytes (8 bits), so the FileReader class reads the file as a stream of characters, FileInputStream reads the file by byte stream; InputStreamReader can convert read as stream into character stream, which is the bridge between reader and stream.? Originally Java was not supporting the processing of text files, in order to compensate for this shortcoming introduced the reader and
( FileInputStream));Third, FileInputStreamA superclass of all byte input streams, used for reading bytes. as already mentioned, one of the arguments applied when instantiating a InputStreamReader objectcan pass file path name pathname or file object instantiationFour, read the filethe BufferedReader object uses the ReadLine () method to determine whether the string is null to determine whether it is the end of the fileString Read; while ((Read=buffe
java io Stream is the input and output stream, the stream is a set of sequential, with the beginning and end of the byte combination, is the general name of the data transmission. That is, the transmission of data between two devices is called a stream, and the nature of the flow is data transmission. the IO stream can be divided into byte stream and character stream. Give the corresponding IO structure diagram:in the next period of time, will slowly
have been confused FileReader FileInputStream InputStreamReader bufferedreader The difference between the connection, each write read the document Java program is online Baidu. This issue was discussed in depth today.First, the sourceJava.io has two abstract class InputStream and Reader, the above classes are inherited by these two super classes. The difference between them is that InputStream is the input
read results returned:" +Fis.read (b)); System.out.println ("After reading, the contents of array B are:" +arrays.tostring (b)); } fis.close (); }}The output is consistent with the original result:The 1th reads the returned result: 2, after reading the contents of the array B is: [, 1] The 2nd reads the result of the return:1, after reading the contents of the array B is: [Wuyi,] 3rd reads the result of the return:-the second reading of the contents of array B is: [51, 80°Icon:The unders
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.