帮我看看这段代码...!
package marks;
import java.io.*;
public class persons {
public static void main(String[] args)
{
try
{
String head = "Name,ID,DS,DB ";
byte[] c = new byte[40];
c = head.getBytes();
System.out.println(c);
FileOutputStream fo = new FileOutputStream( "c:\\student.txt ");
byte [] name = new byte[40];
byte [] id = new byte[4];
byte [] ds = new byte[3];
byte [] db = new byte[3];
System.in.read(name);
System.in.read(id);
System.in.read(ds);
System.in.read(db);
String sName = new String(name);
String sId = new String(id);
String sDs = new String(ds);
String sDb = new String(db);
String record = "\n "+sName+ ", "+sId+ ", "+sDs+ ", "+sDb;
c = record.getBytes();
fo.write(c);
fo.close();
}
catch(
FileNotFoundException fe)
{
System.out.println( "File Not Found ");
}
catch(
IOException ie)
{
System.out.println( "IO Exception ");
}
}
}
执行程序没有错.但是我输入数据以后,输入的信息没有保存到文本文件里面,
请高手帮我看看哪里有问题,
------解决方案--------------------import java.io.*;
public class Demo {
public static void main(String[] args) {
try {
String head = "Name,ID,DS,DB ";
byte[] c = new byte[40];
c = head.getBytes();
System.out.println(c);
BufferedWriter fo = new BufferedWriter(new FileWriter( "d:\\student.txt "));
String[] info = new String[4];
BufferedReader reader = new BufferedReader(new InputStreamReader(System.in));
for (int i = 0; i < info.length; i++) {
info[i] = reader.readLine();
}
String record = " ";
for(String s : info) {
record += s;
}
fo.write(record);
fo.close();
} catch (File
NotFoundException fe) {
System.out.println( "File Not Found ");
} catch (IOException ie) {
System.out.println( "IO Exception ");
}
}
}