Write multiple TXT files to one TXT file

Source: Internet
Author: User

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

Contact Us

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.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.