Java Exercise: Read the contents of the file and sort it in a natural order and output it to another file

Source: Internet
Author: User

 PackageCom.swift;ImportJava.io.FileInputStream;Importjava.io.FileNotFoundException;ImportJava.io.FileOutputStream;Importjava.io.IOException; Public classio_sort_content { Public Static voidMain (string[] args) {/** The contents of the known file A.txt file are "Bcdeadferwplkou", * please write the program to read the contents of the file, and in natural order after the output to the B.txt file. * That is, the contents of the file in B.txt should be "ABCD ..."         In this order. */            Try{FileInputStream fis=NewFileInputStream ("E:\\neck\\a.txt"); FileOutputStream Fos=NewFileOutputStream ("E:\\neck\\b.txt"); byte[] kilo=New byte[4*1024]; intLen;  while((Len=fis.read (kilo))!=-1) {fos.write (kilo,0, Len);                    Fos.flush (); }            } Catch(FileNotFoundException e) {e.printstacktrace (); } Catch(IOException e) {e.printstacktrace (); }    }}

Above just do read and write another file, and not sort

Here's how to sort

Java Exercise: Read the contents of the file and sort it in a natural order and output it to another file

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.