Java Export List collection to TXT file--(iv)

Source: Internet
Author: User

Sometimes, you need to export the data to a TXT file in a certain format. With Java io, you can easily export data to txt.

1  PackageAction.txt;2 3 ImportJava.io.BufferedWriter;4 ImportJava.io.File;5 ImportJava.io.FileOutputStream;6 ImportJava.io.OutputStreamWriter;7 ImportJava.io.Writer;8 Importjava.util.ArrayList;9 Importjava.util.List;Ten  One Importorg.junit.Test; A  - ImportBean. Question; -  the /*[Dry] anti-lock braking system (ABS) Under what circumstances can the maximum performance of the brakes be played? - [Type] Radio - [option]{a: Intermittent braking},{b: continuous braking},{c: Emergency braking},{d: slow pedal brake pedals} - [Answer]c + [The purpose of the analysis]abs is to prevent the brakes when the foot of death, resulting in a rollover or something. However, brake brakes are relatively slow (speed n fast time), the effect is equal to the brakes, and then Panasonic brakes, repeated several times! */ -  Public classExporttxtpaper { +  A     Private StaticFile OutFile =NewFile ("Test.txt"); at  -     /** - * Generate a single selection template -      *  -      * @paramNum - * Number of single selection in      */ -      Public Static voidExporttxtpaper (list<question>list) { to  + Writer out; -         Try { theout =NewBufferedWriter (NewOutputStreamWriter (NewFileOutputStream (OutFile,true), "Utf-8"), 10240); *              for(inti = 0; I < list.size (); i++) { $ Out.write (Panax Notoginseng"[Dry]" +list.get (i). Gettimu () + -"\r\n[Type]" +List.get (i). getleixing () the+ "\r\n[a option]" +List.get (i). Getaxuanxiang () ++ "\r\n[b option]" +List.get (i). Getbxuanxiang () A+ "\r\n[c option]" +List.get (i). Getcxuanxiang () the+ "\r\n[d option]" +List.get (i). Getdxuanxiang () ++ "\r\n[Answer" +List.get (i). Getdaan () -+ "\r\n[Parse]" +list.get (i). Getjiexi () + "\ r \ n"); $Out.write ("\ r \ n"); $             } - Out.flush (); - out.close (); the}Catch(Exception E1) { -             //TODO auto-generated Catch blockWuyi e1.printstacktrace (); the         } -     } Wu  -      About     /** $ * Test Generation template -      */ - @Test -      Public voidtest1 () { A          +list<question> list =NewArraylist<>(); theList.add (NewQuestion ("What do you like to eat", "Radio", "Old Driver", "convenient", "spicy", "milk", "Old driver", "I am the old driver")); -List.add (NewQuestion ("What do you like to eat", "Radio", "Old Driver", "convenient", "spicy", "milk", "Old driver", "I am the old driver")); $List.add (NewQuestion ("What do you like to eat", "Radio", "Old Driver", "convenient", "spicy", "milk", "Old driver", "I am the old driver")); theList.add (NewQuestion ("What do you like to eat", "Radio", "Old Driver", "convenient", "spicy", "milk", "Old driver", "I am the old driver")); theList.add (NewQuestion ("You Are Human", "Judging", "", "", "", "", "yes", "I am the old driver")); theList.add (NewQuestion ("You Are Human", "Judging", "", "", "", "", "yes", "I am the old driver")); the exporttxtpaper. Exporttxtpaper (list); -     } in}

Results:

Java Export List collection to TXT file--(iv)

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.