I'm trying to parse a file like this:
textfile.txt
_=1406048396605
bh=1244
bw=1711
c=24
c19=DashboardScreen
c2=2014-07-22T10:00:00-0700
c4=64144090210294
c40=3#undefined#0#0#a=-2#512#-1#0
c41=14060470498427c3e4ed
c46=Green|firefox|Firefox|30|macx|Mac OS X
c5=NONFFA
c6=HGKhjgj
c7=OFF_SEASON|h:PARTIAL|
ch=YHtgsfT
g=https://google.hello.com
h5=77dbf90c-5794-4a40-b1ab-fe1c82440c68-1406048401346
k=true
p=Shockwave Flash;QuickTime Plug-in 7.7.3;Default Browser Helper;SharePoint Browser Plug-in;Java Applet Plug-in;Silverlight Plug-In
pageName=DashboardScreen - Loading...
pageType=
pe=lnk_o
pev2=pageDetail
s=2432x1520
server=1.1 pqalmttws301.ie.google.net:81
t=22/06/2014 10:00:00 2 420
v12=3468337910
v4=0
v9=dat=279333:279364:375870:743798:744035:743802:744033:743805:783950:783797:783949:784088
vid=29E364C5051D2894-400001468000F0EE
into something like this:
_=1406048396605<CONTROL_CHARACTER_HERE>bh=1244<CONTROL_CHARACTER_HERE>bw=1711<CONTROL_CHARACTER_HERE>c=24<CONTROL_CHARACTER_HERE>c19=DashboardScreenc2=2014-07-22T10:00:00-0700.....etc
So I'm basically taking a multiline file and making it into a single line file delimiting each field with a CONTROL_CHARACTER.
This is what I currently have:
private String putIntoExpectedFormat() {
File f1 = new File("InputFile.txt");
File f2 = new File("OutputFile.txt");
InputStream in = new FileInputStream(f1);
OutputStream out = new FileOutputStream(f2);
StringBuilder sb = new StringBuilder();
byte[] buf = new byte[1024];
int len;
while( (len=in.read(buf)) > 0) {
out.write(buf,0,len);
}
in.close();
out.close();
}
I'm not even sure if I'm doing this right. Does anybody know how to do this?