【发布时间】:2020-02-27 13:34:56
【问题描述】:
void abIn()throws IOException
{
FileOutputStream fos=new FileInputStream("abc.dat");
DataOutputStream dos = new DataInputStream(fos);
BufferedReader br=new BufferedReader(new InputStreamReader(System.in));
for(int i=0;i<5;i++)
{
System.out.println("Enter PC, Price Quantity "+(i+1));
pc=Integer.parseInt(br.readLine());
up=Double.parseDouble(br.readLine());
q=Integer.parseInt(br.readLine());
dos.writeInt(pc);
dos.writeDouble(up);
dos.writeInt(q);
}
dos.close();
fos.close();
}
void abOut()throws IOException
{
FileInputStream fin=new FileInputStream("ABC.DAT");
DataInputStream din=new DataInputStream(fin);
BufferedReader br=new BufferedReader(new InputStreamReader(System.in));
System.out.println("Enter Product Code");
int x=Integer.parseInt(br.readLine());
boolean EOF =false;
while(!EOF)
{
try
{
int pcx =din.readInt(pc);
int upx=din.readDouble(up);
int qx=din.readInt(q);
if(pcx==x)
{
System.out.println(pcx+" "+upx+" "+q);
}
}
catch(EOFException e)
{}
}
din.close();
fin.close();
}
public static void main()throws IOException
{
f1 ob=new f1();
ob.abIn();
ob.abOut();
}
返回未知的编译时间错误。 我尝试使用 Java 中的产品代码、产品价格和数量(单位)创建一个 dat 文件,然后使用产品代码搜索并获取上述输入的其他详细信息。
【问题讨论】:
-
请将堆栈跟踪添加到您的问题中。
-
究竟是什么错误(请复制并粘贴)。
-
拥有完整的代码会有所帮助。我尝试编译,由于缺少outer class关键字而失败。
-
实际上我知道我必须使用 FileWriter 而不是 FileOutputStream 但接下来的问题是如何使用 File reader 命令显示。
-
而事实是外部类是类 abc 一个在它之上的头文件,即导入 java.io.*;