java - How to Read one file and generating multiple text output file -
i hava 1 text file below. question want read txt file upto each 1 paragraph , generating separate new text file each 1 on java
>t0646 or188, , 93 residues mqeerkklleklekildevtdgapdearerieklakdvkdeleegdaknmiekfrdemeq mykdapnavmeqlleeiekllkkagslvprgsy >t0647 hr5514a, , 157 residues mterlsaeqikeykgvfemfdeegngevktgelewlmsllginptkselasmakdvdrdn kgfffncdgflalmgvyhekaqnqeselraafrvfdkegkgyidwntlkyvlmnagepln eveaeqmmkeadkdgdrtidyeefvammtgesfkliq >t0648 cpn10, , 102 residues magqafrkflplfdrvlversaaetvtkggimlpeksqgkvlqatvvavgsgskgkggei qpvsvkvgdkvllpeyggtkvvlddkdyflfrdgdilgkyvd
public class test{ public static void main (string[] args){ bufferedreader br=null; bufferedwriter bw= null; file file = new file("...desktop\\new folder\\out.txt"); try { string s; string text = ""; br = new bufferedreader(new filereader( "....desktop\\new folder\\casp10.txt")); filewriter fw = new filewriter(file.getabsolutefile()); bw = new bufferedwriter(fw); while ((s=br.readline())!= null) { if(s.contains(">")){ string line=br.readline(); if(line!=null) { system.out.println(line); bw.write('\n'+ line ); } } bw.write(s +"\n"); } } catch(ioexception e) { e.printstacktrace(); } { try { if(br!=null) { br.close(); bw.close(); } } catch(ioexception e) { e.printstacktrace(); } } } }
invokes every time want print different writer
public class mysaver{ private printwriter innerwriter; public mysaver(writer writer) { this.innerwriter = new printwriter(writer); } public void save(string c) throws ioexception { innerwriter.write(c); } }
or first create string stringbuilder , append , print its. string builder doc
Comments
Post a Comment