我正在为我的 CS java 课程做作业,我收到了下面列出的错误。第二条水平线下方是源代码。还有一个用于运行 Crypto.java 的附加 java 程序文件,名为 Lab13.java,我不太了解异常逻辑。代码和我澄清的问题在底部。
Crypto.java:9: error: no suitable constructor found for FileInputStream(String[])
FileInputStream inStream = new FileInputStream(existing);
^
constructor FileInputStream.FileInputStream(FileDescriptor) is not applicable
(actual argument String[] cannot be converted to FileDescriptor by method invocation conversion)
constructor FileInputStream.FileInputStream(File) is not applicable
(actual argument String[] cannot be converted to File by method invocation conversion)
constructor FileInputStream.FileInputStream(String) is not applicable
(actual argument String[] cannot be converted to String by method invocation conversion)
Crypto.java:12: error: no suitable constructor found for FileOutputStream(String[])
FileOutputStream outStream = new FileOutputStream(encrypted);
^
constructor FileOutputStream.FileOutputStream(FileDescriptor) is not applicable
(actual argument String[] cannot be converted to FileDescriptor by method invocation conversion)
constructor FileOutputStream.FileOutputStream(File,boolean) is not applicable
(actual and formal argument lists differ in length)
constructor FileOutputStream.FileOutputStream(File) is not applicable
(actual argument String[] cannot be converted to File by method invocation conversion)
constructor FileOutputStream.FileOutputStream(String,boolean) is not applicable
(actual and formal argument lists differ in length)
constructor FileOutputStream.FileOutputStream(String) is not applicable
(actual argument String[] cannot be converted to String by method invocation conversion)
2 errors
这是源代码:
import java.io.*;
public class Crypto
{
public static void encryptFile(String existing[], String encrypted[]) throws IOException
{
boolean eof = false;
FileInputStream inStream = new FileInputStream(existing);
DataInputStream inFile = new DataInputStream(inStream);
FileOutputStream outStream = new FileOutputStream(encrypted);
DataOutputStream outFile = new DataOutputStream(outStream);
while (!eof)
{
try
{
byte input = inFile.readByte();
int c = (input * 137) % 256;
outFile.writeByte(c);
}
catch(EOFException e)
{
eof = true;
}
}
outFile.close();
}
}
所以就像我说的,下一部分用于运行 Crypto。当它捕获 IOException 时它到底在做什么?它是否会显示 EOF 异常错误消息,因为它是从执行 Crypto.encryptFile 的 try 语句中捕获的?
import java.io.*;
public class Lab13
{
public static void main (String[] args)
{
try
{
Crypto.encryptFile("MyLetters.txt", "Encrypted.txt");
System.out.println("done.");
}
catch (IOException e)
{
System.out.println("Error- " + e.getMessage());
}
}
}