Today, we encountered a tedious problem at work, that is, we downloaded dozens of keys, which are divided into different TXT files, however, we need to import keys in batches in the same TXT file during the import process, so the stupid way is to manually Ctrl + C, CTRL + V, these dozens of files are not only inefficient, but also prone to errors. To this end, I thought of using Java file classes for operations.
Although I have studied software engineering in college, I have never studied it carefully. I am not looking for a development job, so I don't understand a lot of basic knowledge. So I have to look for javaapi.
The following code copies the contents of multiple TXT files to one TXT file:
Package AAAA; import Java. io. filereader; import Java. io. filewriter; import Java. io. ioexception; public class testfilewriter {public static void main (string [] ARGs) {filereader Fr = NULL; filewriter fw = NULL; int n = 24; int B = 0; system. out. println ("Don't blink, copying ...... "); Try {// repeatedly copy multiple TXT files to the target file for (INT I = 1; I <= N; I ++) {Fr = new filereader ("d :\\ miyao \ 2014-07-23 key (" + I + "cmd.txt"); // file to be copied fw = new filewriter ("D: \ miyao \ 2014-07-23cipher .txt ", true); // the location of the saved file. True indicates that the operation while (B = Fr. read ())! =-1) {FW. write (B); FW. flush () ;}} catch (exception e) {e. getmessage (); E. printstacktrace ();} finally {try {Fr. close (); FW. close ();} catch (ioexception e) {e. getmessage (); E. printstacktrace () ;}} system. out. println ("Copied successfully, please go to the miyao directory of drive d to view ");}}
This not only improves the efficiency, but also prevents errors. After writing this code, I am very excited. Although it is just a basic knowledge, it brings convenience and happiness to my work!
If you have more time in the future, you should learn more java knowledge. Come on!
Note: When Using cmd to compile and run the Java file, the compilation can pass, but the running reports cannot find the main class:
After checking on the internet, Java cannot find the compiled. Class file.
One solution: Java-classpath,; testfilewriter