Help with formatting output data

I need help with a program I am writing where I am reading data from a file, then as I am reading the data from the file I am to pass the data to a method which will format the string then this will be outputted to a new file, once I have processed all data to the file I then have to reopen the file and read the contents of the file and output it to the user. The problem I am having with the program is figuring out how to format the data as it is read from the file, I think I am suppose either the printf() function or the string.format()If anyone can help I would be greatly appreciated!

The layout of the input file is:
name t1 t2 t3 t4 t5
The layout of the output file is:
name (columns 1 - 12, field width = 12, left-justified
t1 (columns 13 15, field width = 3, right-justified)
t2 (columns 16 18, field width = 3, right-justified)
t3(columns 19 21, field width = 3, right-justified)
t4 (columns 22 24, field width = 3, right-justified)
t5 (columns 25 27, field width = 3, right-justified)

import java.util.*;
import java.io.* ;
import java.lang.*;
public class dataformat
{
public static void main (String[] args) throws Exception
{
Scanner sc = new Scanner(new File("C:\280-03-data.txt"));
PrintWriter outFile = new PrintWriter(new FileWriter ("C:\280-03-out.txt"));

while (sc.hasNext())
{
String strInput = sc.nextLine();
int length = strInput.length();
outFile.println(FixSize(strInput,length));
}
outFile.close();
Scanner scan =new Scanner(new File("C:\280-03-out.txt"));

while(scan.hasNext())
{
String output= scan.nextLine();
System.out.println(output);
System.out.println(" ");
}

outFile.close();
}

public static String FixSize(String Input, int intFieldWidth)
{

if (intFieldWidth <= 27)
{
}
return Input;
}
}





Sign In or Register to comment.

Howdy, Stranger!

It looks like you're new here. If you want to get involved, click one of these buttons!

Categories