java 读取sh000001.day
时间: 2023-07-18 19:34:55 浏览: 105
Day01.java
要读取sh000001.day文件,可以使用Java中的FileInputStream和DataInputStream类。代码如下:
```
import java.io.*;
public class ReadSH000001Day {
public static void main(String[] args) {
String filePath = "sh000001.day";
try {
FileInputStream fis = new FileInputStream(filePath);
DataInputStream dis = new DataInputStream(fis);
// 读取文件头
int fileHeader = dis.readInt();
System.out.println("File Header: " + fileHeader);
// 读取数据记录数
int recordCount = dis.readInt();
System.out.println("Record Count: " + recordCount);
// 读取数据记录
for (int i = 0; i < recordCount; i++) {
int date = dis.readInt();
float openPrice = dis.readFloat();
float highPrice = dis.readFloat();
float lowPrice = dis.readFloat();
float closePrice = dis.readFloat();
float volume = dis.readFloat();
float amount = dis.readFloat();
System.out.println(date + "," + openPrice + "," + highPrice + "," + lowPrice + "," + closePrice + "," + volume + "," + amount);
}
dis.close();
fis.close();
} catch (IOException e) {
e.printStackTrace();
}
}
}
```
这段代码会读取sh000001.day文件中的数据,并将其输出到控制台。注意,这里只是简单的将数据输出,实际应用中可能需要对数据进行处理和分析。
阅读全文