public class Gencategoryattritemhandler {private final static String Input_file_path = "Input/category_attr_item.txt"; Private final static String Output_flie_path = "Output/category_attr_itemlist.txt";/** * @param args * @throws IOException */public static void Main (string[] args) throws IOException {//TODO auto-generated method Stubgetdatafromfile (); Writedatatofile (); System.out.println ("OK");} /** * Extract data from a file. Format to program * @throws ioexception */public static void Getdatafromfile () throws IOException {final String DELIMITER = "\ t"; BufferedReader br = null;try {File File = new file (input_file_path); br = new BufferedReader (new InputStreamReader (new file InputStream (file), "UTF-8"); String line = Null;while (null! = (Line=br.readline ())) {string[] STRs = Line.split (DELIMITER); Category category = new category (Long.parselong (Strs[0]), strs[1]); Attribute Attribute = new Attribute (Long.parselong (strs[2]), strs[3]); Item item = new Item (Long.parselong (STRS[4)), STRs [5]); ...} While} catch (Exception e) {E.printstacktrace ();} finally {if (null! = BR) {br.close ();}}} /** * Writes formatted data to a file * @throws ioexception */public static void Writedatatofile () throws IOException {final String delimite R = "\ t"; BufferedWriter bw = null;try {File File = new file (output_flie_path); bw = new BufferedWriter (New OutputStreamWriter Leoutputstream (file), "UTF-8")), for (int i=1; i<12; ++i) {... bw.write (outvalue); Writes data to a file Bw.newline (); Create a new newline character bw.flush ();}} catch (Exception e) {e.printstacktrace ();} finally {if (null! = BW) {bw.close ();}}}}
Copyright notice: This article blog original articles, blogs, without consent, may not be reproduced.
Java Read TXT file