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)