• Post Reply Bookmark Topic Watch Topic
  • New Topic
programming forums Java Mobile Certification Databases Caching Books Engineering Micro Controllers OS Languages Paradigms IDEs Build Tools Frameworks Application Servers Open Source This Site Careers Other Pie Elite all forums
this forum made possible by our volunteer staff, including ...
Marshals:
  • Campbell Ritchie
  • Tim Cooke
  • Liutauras Vilda
  • Jeanne Boyarsky
  • paul wheaton
Sheriffs:
  • Ron McLeod
  • Devaka Cooray
  • Henry Wong
Saloon Keepers:
  • Tim Holloway
  • Stephan van Hulst
  • Carey Brown
  • Tim Moores
  • Mikalai Zaikin
Bartenders:
  • Frits Walraven

How to split the text file individually.

 
Greenhorn
Posts: 9
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Hi,

I am looking to split the line in the text file to individual text file.

Example in my current text file(RetrieveFile.txt):
<?xml version="1.0" encoding="UTF-8"?><ERRORACK><HEADER><MESSAGE_TYPE>ErrorAck</MESSAGE_TYPE><MESSAGE_ID>20160104171116001</MESSAGE_ID><ERROR_FILE>SCPreClrDec</ERROR_FILE><SEND_DATETIME>2016-01-04T17:11:16</SEND_DATETIME></HEADER><DETAIL><ERRORACK_ID>CERR20160104171116000001</ERRORACK_ID><RECORD_ID>CDCC20070604010101000001</RECORD_ID><REASON><REASON_CODE>908</REASON_CODE><REASON_REMARK>Container Information Not Found</REASON_REMARK></REASON></DETAIL></ERRORACK>

<?xml version="1.0" encoding="UTF-8"?><ERRORACK><HEADER><MESSAGE_TYPE>ErrorAck</MESSAGE_TYPE><MESSAGE_ID>20160104170749001</MESSAGE_ID><ERROR_FILE>SCPreClrDec</ERROR_FILE><SEND_DATETIME>2016-01-04T17:07:49</SEND_DATETIME></HEADER><DETAIL><ERRORACK_ID>CERR20160104170749000001</ERRORACK_ID><RECORD_ID>CDCC20070604010101000001</RECORD_ID><REASON><REASON_CODE>908</REASON_CODE><REASON_REMARK>Container Information Not Found</REASON_REMARK></REASON></DETAIL></ERRORACK>

I want to split into RetrieveFile1 and RetrieveFile2 but i do not know how to split it. Here is my code for it.
public class split {

Much help needed. Am just a beginner in java role. Thank you



 
Sheriff
Posts: 28321
95
Eclipse IDE Firefox Browser MySQL Database
  • Likes 1
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Hi kelvin, welcome to the Ranch!

I don't know how to split it either, because you didn't say what your requirements are. Do you want to write each line into a separate file? Or what? You can't get started on programming if you don't have specific requirements.
 
kelvin Seow
Greenhorn
Posts: 9
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Hi,

Yup so in retrieveFile.txt which have 2 big chunk of text i want it split into 2 text file

retrieveFile original text:
<MESSAGE_ID>20160104171116001</MESSAGE_ID>
<MESSAGE_ID>20160104140060012</MESSAGE_ID>

1.retrieveFile1.txt will contain this.
<MESSAGE_ID>20160104171116001</MESSAGE_ID>

2. retrieveFile1.txt will contain this
<MESSAGE_ID>20160104140060012</MESSAGE_ID>

So i want to like save each line of text into new files is it possible?
 
Paul Clapham
Sheriff
Posts: 28321
95
Eclipse IDE Firefox Browser MySQL Database
  • Likes 1
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Of course it's possible. You have a loop which reads through each line of the input file. So for each line here's what you need to do:

1. Open a new output file with a suitably numbered name. (You have code to do that, just in the wrong place.)

2. Write the line to that file.

3. Close that file.
 
kelvin Seow
Greenhorn
Posts: 9
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
can i use count? is my count statement wrong?

If i put my writer.close inside
[/code]
 
kelvin Seow
Greenhorn
Posts: 9
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Another question sometimes XML have those whitespaces.

XML file.
<?xml version="1.0" encoding="UTF-8"?>
<PERMIT>
<PERMIT_HEADER>

how do i trim it so i when i do the splitting it wont appear as

1. <?xml version="1.0" encoding="UTF-8"?> - 1 text file
2. <PERMIT> - 1 text file
3. <PERMIT_HEADER> - 1 text file

Many thanks.
 
kelvin Seow
Greenhorn
Posts: 9
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
I solved both issues!! Thank you Paul
 
Evildoers! Eat my justice! And this tiny ad's justice too!
Gift giving made easy with the permaculture playing cards
https://coderanch.com/t/777758/Gift-giving-easy-permaculture-playing
reply
    Bookmark Topic Watch Topic
  • New Topic