Get the Beginning Position Of a field
<p>Hi Guys I am writing a code that reads a text file in this format:</p>

<pre><code>City             |First Name| Second Name|Last Name|
</code></pre>

<p>The output I currently have is :</p>

<pre><code>Column 1 is 17--------City
Column 2 is 10--------First Name
Column 3 is 12--------Second Name
Column 4 is 9---------Last Name
</code></pre>

<p>I need the Begin Position Also Of each Field in the Text File for example:</p>

<pre><code>Column 1 is 17--------City : Position 1
Column 2 is 10--------First Name: Position 18
Column 3 is 12--------Second Name: Position 31
Column 4 is 9---------Last Name: Position 44
</code></pre>

<p>Here Is the Code I currently Have. Is there a way to achieve This?</p>

<pre><code> package stanley.column.reader;

 import java.io.*;

 public class StanleyColumnReader {

    public static void main(String[] args) throws IOException {
        System.out.println("Developed By Stanley Mungai");       
        File f = new File("C:/File/");
        if (!f.exists()) {
            f.createNewFile();
        } else {
            f.delete();
        }
        String [] files = f.list();
        for (int j = 0; j &lt; files.length; j++){
            FileInputStream fs = new FileInputStream("C:/File/" + files[j]);
            BufferedReader br = new BufferedReader(new InputStreamReader(fs));
            String result = "_result";
            BufferedWriter is = new BufferedWriter(new FileWriter("C:/File/" + files[j] + result + ".txt"));
            for (int i = 0; i &lt; 0; i++) {
                br.readLine();
            }

            String line = br.readLine();
            String[] split = line.split("|");
            for (int i = 0; i &lt; split.length; i++) {
                int k = i + 1;
                System.out.println("Calculating the size of field " + k );
                is.write("Column " + k + " is " + split[i].length());
                is.flush();
                is.newLine();
            }
        }
        System.out.println("Success");
        System.out.println("Output Saved to C:/File");
    }
}
</code></pre>
