One, the
print flow
1. Overview of the print flow
The print stream adds the ability to output data so that they can easily print various data value representations .
The print flow is categorized according to the flow:
(1) byte print stream PrintStream
(2) character print stream PrintWriter
Method:
void print (String str): Outputs any type of data,
void println(String str): Outputs any type of data, automatically writes a line-break operation
2. Code Demo:
1 //How does the print stream output2 Public Static voidMETHOD5 ()throwsioexception{3 //Clear Data Purpose4FileOutputStream fos=NewFileOutputStream ("E:\\test\\test.txt");5PrintStream ps=NewPrintStream (FOS);6Ps.print ("Zhang San");7Ps.println ("Hello");8Ps.println (true);9 //Freeing ResourcesTen ps.close (); One } A //Print stream Copy file - Public Static voidMethod6 ()throwsioexception{ - //Clear Data Source theFileReader fr=NewFileReader ("E:\\test\\test.txt"); -BufferedReader br=NewBufferedReader (FR); - //Clear Data Purpose -FileWriter fw=NewFileWriter ("E:\\test\\pig.txt"); +PrintWriter pw=NewPrintWriter (FW,true);//Auto Refresh - //Copy +String line=NULL; A while((Line=br.readline ())! =NULL){ atPw.println (line);//Refresh + line break - } - //Freeing Resources - br.close (); - pw.close (); -}
Second, Commons-io1. Guide Package
class files in third-party jar packages that are added to Classpath can be used in projects
Create lib folder
Copy the Commons-io.jar to the lib folder
Right click on commons-io.jar,build path→Add to build path
2.FilenameUtils
This tool class is used to deal with file name (Translator Note: include file path), he can easily solve different operating system file names specification of different issues
Common methods:
GetExtension (String path): Gets the file name extension;
GetName (): Gets the file name;
Isextension (String filename,string ext): Determine If filename is the ext suffix name;
Code implementation:
1 Public Static voidMethod7 () {2 //get a file name extension3String name=filenameutils.getextension ("E:\\test");4 System.out.println (name);5 //get a file name6String filename=filenameutils.getname ("E:\\test\\test.txt");7 System.out.println (filename);8 //determine whether a file ends with what9 BooleanFlag=filenameutils.isextension ("Aaa.java", "Java");Ten System.out.println (flag); One}
3.FileUtils
Provides methods for file operations (moving files, reading files, checking whether files exist, and so on).
Common methods:
Readfiletostring (File file): reads the contents of the files and returns a string;
Writestringtofile (file file,string content): writes contents to file;
Copydirectorytodirectory (File srcdir,file destDir), folder replication
CopyFile (file Srcfile,file destfile);
Code implementation:
1 //Fileutils class2 Public Static voidMethod8 ()throwsioexception{3 //Copy Folder4Fileutils.copydirectory (NewFile ("E:\\test"),NewFile ("E:\\test2"));5 //Copying Files6Fileutils.copyfile (NewFile ("E:\\test\\test.txt"),NewFile ("E:\\test\\test5.txt"));7}
java--Print Flow, Commons-io