j2me如何把已知数组写入dat文件

来源:百度知道 编辑:UC知道 时间:2024/06/15 14:56:45
谢谢,最好详细点说明,谢谢.有追加.
1楼,公司上不了QQ,你贴出来看吧....要不我晚上入群
2楼,万分感谢啊,稍微有点明白了.我以前没接触过I/O.我再捣鼓捣鼓.不明白的再来问.分先不急给哈.为了吸引更多的回答.

测试类..
public static void main( String[] args ) throws IOException
{
File file = new File("1.dat") ;
String[] test = {"test1", "test2", "test3"} ;
FileOutputStream os = new FileOutputStream(file) ;
DataOutputStream dos = new DataOutputStream(os) ;
dos.writeInt(test.length) ;
for ( int i = 0; i < test.length; i++ )
dos.writeUTF(test[i]) ;
dos.close() ;
DataInputStream dis = new DataInputStream(new FileInputStream(file)) ;
int num = dis.readInt() ;
for ( int i = 0; i < num; i++ )
System.out.println(dis.readUTF()) ;
dis.close() ;
os.close() ;
}