")); PrintWriter pw = new PrintWriter (New FileWriter ("D:\\a.txt"), true); String line = null;while (line = Bfr.readline ())!=null) {pw.println (line);} Pw.close (); Bfr.close ();}iv.. commons-io file Tool class1. Get the file name extension/* * Filenameutils class method * static string GetExtension (string filename) * Gets the extension of the
Original link Author: Jakob Jenkov Translator: Li Jing ([email protected])In a Java application, a file is a common source of data or a medium for storing data. So this section will provide a brief overview of the use of files in Java. This article will not explain every technical detail, but will provide you with the necessary knowledge points for the method of
IoMost applications have data exchange with external devices, and the most common external devices include disks and networks. IO refers to the data input and output of these devices by the application, and the Java language defines many classes that are specifically responsible for the input and output of various methods, which are placed in the java.io package.File classThe
Java IO file suffix filtering summary, javaio suffix Filtering
Effect: list specific suffix files under a directory (for example, txt files under the root directory of the D Drive)
Import java. io. file; import
,//stream can manipulate the file object Pro.store (FW, "after Change");}
Iv. Practice
Get the number of uses of an application, more than 3 times, give information about the number of times the usage has been registered, and do not run the program again
Analysis:
This requirement requires a counter, each time the program starts counter into memory, number of times +1, exit program, counter close, store to
use the input character stream inputstreamreader instead of FileReader; he can specify character encoding.* 2. How to efficiently traverse the entire text file* You can use the buffered stream BufferedReader stream to read one line at a time.* @author User**/public class FileOprate2 {public static void Main (string[] args) {File F=new file ("D:\\liu.txt");
In the log file of your WebLogic Server, you may see exception
(Window nt)
Java. Io. ioexception Connection reset by peer
Java. Io. ioexception: clientabortexception: java.net. socketexception: Connection reset by peer: Socket write error
Java IO stream: Random file read/write, javaio stream
The Java. io package provides the RandomAccessFile class for creating and accessing random files. Using this class, you can jump to any position of the file to read and write d
This article is intended to illustrate the basic methods and processes of Java file IO operations as an example.Source1 ImportJava.io.*;2 3 Public classMain {4 Final StaticString filename= "Alice.txt";5 //file name6 Public Static voidMain (string[] args) {7 intCount=1;8String dir=system.getpropert
, booleanownerOnly)Sets the Read permission for the owner or all users of this abstract path name.
boolean
setReadOnly()Marks the file or directory specified by this abstract pathname so that it can be read only.
boolean
setWritable(booleanwritable)A convenient way to set this abstract pathname owner write permission.
boolean
setWritable(booleanwritable, booleanownerOnly)Sets the write permissio
); //Traverse this folder (all files and folder names in the directory) } Private Static voidListall (File file,intLevel ) {System.out.println (Getsapce level)+file.getname ()); //gets all file objects and filenames under the specified directory .File[] F =File.listfiles (); level++; for(
;> 24);//high 8-bit raf.write (i >>>); Raf.write (i >>> 8); Raf.write (i); System.out.println (Raf.getfilepointer ());//You can write a intraf.writeint (i) directly; String s = "medium"; byte[] GBK = s.getbytes ("GBK"); Raf.write (GBK); System.out.println (Raf.length ());//Read the file, you must move the pointer to the head raf.seek (0);//One-time read, read the contents of the file into a byte array byte[
Package IO;Import Java.io.File;Import java.io.IOException;public class FileIO {/*** Build and get file name information* @param args*/public static void FileName (string[] args) {SYSTEM.OUT.PRINTLN ("Path delimiter:" +file.pathseparator); Path delimiterSystem.out.println ("Name delimiter:" +file.separator);//Name delimiterRelative path to the project as the starting path to find the corresponding
optimized to form a UTF-8, one byte in the UTF-8 can not be installed with two, 2 can not be installed with 3 ······. So the problem occurred, when we write Chinese, GBK recognition, but the UTF-8 also identified. However, the binary encoding of the same Chinese Character in the two tables is different, and garbled characters appear. In this case, the ghost stream can be integrated into the internal encoding table, that is, you can specify the encoding table to be checked.
/*** 1. The
this channel ' s file to the given writable byte* Channel.* * That reads from this channel and writes to the target channel. Many* Operating systems can transfer bytes directly from the filesystem cache* to the target channel without actually copying them. Public Abstract Long transferTo (long position, long count,writablebytechannel target)throws IOException;The above is the new method of FileChannel.The FileInputStream member variables in the I/O
(string[] args) { file F=new file ("D:" +file.sep arator+ "test"); F.mkdir ();//Create Folder }} instance Action five: List all files for a specified directory if you now have a directory, you can list the contents of the directory directly. However, there are two methods listed in the File class:
Returned as an array of strings: pub
Java (IO) read-write file garbled conversion UTF-8 problemRead file String? Content?=?"";?//It is recommended to use StringBuffer if the document is very long Try? {FileInputStream FS=NewFileInputStream ("Document Admission")); Inputstreamreader?isr?=?New? InputStreamReader (FIS,? ") UTF-8 "); Bufferedreader?br?=?N
System.out.println (File.getname ());//directory name System.out.pri Ntln (File2.getname ());//File name System.out.println (File.getparent ());//Parent directory path SYSTEM.OUT.PRINTLN (file.getparen T ());//path to parent directory}}2. Traversing the Directory PackageCom.test.io;ImportJava.io.File;Importjava.io.IOException;/*** Common operation of File class *@authorAdministrator **/ Public classFileUti
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.