create fixed length flat file with Java
- by Leslie
I have a process that currently runs in a Delphi application that I wrote and I need to convert it to a Java process that will run on our web application. Basically our State Financial (legacy) system requires this file in a specific output. In Delphi it is like this:
procedure CreateSHAREJournalFile(AppDate : string; ClassCode : string; BudgetRef : String; AccountNumber : string; FYEStep : integer);
var
GLFileInfo : TStrings;
MPayFormat, HPayFormat, TPayFormat : string;<br>
const<br>
//this is the fixed length format for each item in the file<br>
HeaderFormat = '%-1s%-5s%-10s%-8s%-12s%-10s%-21s%-3s%-71s%-3s%-20s%-1s';<br>
DetailFormat = '%-1s%-5s%-9s%-10s%-10s%-10s%-10s%-8s%-6s%-5s%-5s%-5s%-8s%-25s%-10s%-60s%-28s%-66s%-28s';<br>
begin<br>
try<br>//get the data from the query<br>
with dmJMS.qryShare do<br>
begin<br>
SQL.Clear;<br>
SQL.Add('SELECT SUM(TOTHRPAY) As HourPay, SUM(TOTMLPAY) As MilePay, SUM(TOTALPAY) AS TotalPay FROM JMPCHECK INNER JOIN JMPMAIN ON JMPCHECK.JURNUM = JMPMAIN.JURNUM WHERE PANELID LIKE ''' + Copy(AppDate, 3, 6) + '%'' ');<br>
if FYEStep > -1 then<br>
SQL.Add('AND WARRANTNO = ' + QUotedStr(IntToStr(FYEStep)));<br>
Active := True;<br>
//assign totals to variables so they can be padded with leading zeros<br>
MPayFormat := FieldByName('MilePay').AsString;<br>
while length(MPayFormat) < 28 do <br>MPayFormat := '0' + MPayFormat;<br>
HPayFormat := FieldByName('HourPay').AsString;<br>
while length(HPayFormat) < 28 do <br>HPayFormat := '0' + HPayFormat;<br>
TPayFormat := Format('%f' ,[(FieldByName('TotalPay').AsCurrency)]);<br>
while length(TPayFormat) < 27 do<br>
TPayFormat := '0' + TPayFormat;<br>
TPayFormat := '-' + TPayFormat;<br>
//create a TStringlist to put each line item into<br>
GLFileInfo := TStringList.Create;<br>
//add header info using HeaderFormat defined above<br>
GLFileInfo.Add(Format(HeaderFormat, ['H', '21801', 'NEXT', FormatDateTime('MMDDYYYY', Today), '', 'ACTUALS', '', 'EXT', '', 'EXT', '', 'N']));<br>
//add detail info using DetailFormat defined above<br>
GLFileInfo.Add(Format(DetailFormat, ['L', '21801', '1', 'ACTUALS', AccountNumber, '', '1414000000', '111500', '', '01200', ClassCode, '', BudgetRef, '', AccountNumber + '0300', '', MPayFormat, '', MPayFormat]));<br>
GLFileInfo.Add(Format(DetailFormat, ['L', '21801', '2', 'ACTUALS', AccountNumber, '', '1414000000', '111500', '', '01200', ClassCode, '', BudgetRef, '', AccountNumber + '0100', '', HPayFormat, '', HPayFormat]));<br>
GLFileInfo.Add(Format(DetailFormat, ['L', '21801', '3', 'ACTUALS', '101900', '', '1414000000', '111500', '', '01200', ClassCode, '', BudgetRef, '', '', '', TPayFormat, '', TPayFormat]));<br>
//save TStringList to text file<br>
GLFileINfo.SaveToFile(ExtractFilePath(Application.ExeName) + 'FileTransfer\GL_' + formatdateTime('mmddyy', Today) + SequenceID + '24400' + '.txt');<br>
end;<br>
finally<br>
GLFileINfo.Free;<br>
end;
end;
is there an equivalent in Java for the Format option? Or the TStringList that saves to a text file?
Thanks for any information....haven't done a lot of Java programming!
Leslie