Pages

Monday, March 8, 2010

Reading Metastock files

This example below shows how to read the Metastock MASTER file and list all the Stocks on it:

Expert version:
package wcursino.metastock;

import java.io.*;

public class Reader {
    public static void main(String[] args) throws Exception {

        File f = new File("quotes\\MASTER");
        byte[] data = new byte[(int) f.length()];
        new FileInputStream(f).read(data);

        for (int i = 0; i < ((data.length / 53) - 1); ++i)
            System.out.println(new String(data, ((i + 1) * 53) + 7, 16).trim() + ": "
                    + new String(data, ((i + 1) * 53) + 36, 14).trim());
    }
}

I'm working on a Java code that reads and writes Metastock files.

No comments :