急!!!求写文件方法
搞C++的,最近有个项目要用到java,对java了解,想问一下,我有一个short[]数组,怎么才能直接把它写到文件里面去,我看java提供的写文件都是写 char[]或byte[]的,没有short[]的
[解决办法]
for example
import java.io.*;RandomAccessFile raf = new RandomAccessFile("test.txt", "rw");short[] data = {1,2,3,4,5};for (short s : data) { raf.writeShort((int)s);}raf.close();
[解决办法]
PrintWriter writer = new PrintWriter(new FileWriter("result.txt"));
short[] numbers = ...;
for(short number: numbers){
writer.println(number);
}