大智慧解析到txt

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

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

// 输入流

list = new ArrayList<Vector<Comparable>>();
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();
}

}

}
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值