大智慧解析到txt

还存在一点就是输出在txt中的数据连在一起,没有明显的分行,现在在美化一下,然后在把数据库用进来

/**
* 大智慧新一代行情,大智慧Level-2的格式日线(.dat)格式转换为(.txt)文档格式
具体程序描述如下* */
private static ArrayList> list;
public static void main(String[] args) throws Exception {
DataInputStream in = null;
File f = new File("F:/gupiao.txt");

// 输入流

list = new ArrayList>();
FileOutputStream fos = new FileOutputStream(f);
PrintWriter pw = new PrintWriter(fos,true);
try {
in = new DataInputStream(new BufferedInputStream(
new FileInputStream(new File("E:/股票/dzh2/data/sz/day.dat"))));
} catch (FileNotFoundException fileNotFoundException) {
fileNotFoundException.printStackTrace();

}
try {

in.skipBytes(266240);// 跳过前面的数据
Vector vt = new Vector();
DateFormat riqi = new SimpleDateFormat("yyyy-MM-dd");

for (int i = 0; i < 8; i++) {

byte[] bt = new byte[4];

in.read(bt);
// 如果是日期的情况

if (i == 0) {

String dateFormat = riqi
.format(new Date(
1000 * (long) ((bt[3] & 0xff) << 24
| (bt[2] & 0xff) << 16
| (bt[1] & 0xff) << 8 | (bt[0] & 0xff)))).toString();

vt.add(dateFormat);
//out.StringWriter(dateFormat,0,dateFormat.length());

System.out.println("日期: " + dateFormat);
pw.write(dateFormat);
pw.flush();


}
else{

Float dateFloat = new Float(Float
.intBitsToFloat((bt[3] & 0xff) << 24
| (bt[2] & 0xff) << 16
| (bt[1] & 0xff) << 8 | (bt[0] & 0xff)));

vt.add(dateFloat);
System.out.println(dateFloat);
pw.print(dateFloat );

pw.flush();
//out.writer(dateFloat,0,dateFloat.length());
}


in.skipBytes(4);

}

list.add(vt);

} catch (IOException e) {

// TODO Auto-generated catch block

e.printStackTrace();

} finally {
if (in != null)
in.close();
if (pw != null) {
pw.close();
}

}

}

你可能感兴趣的:(学习小结,F#)