I'm working on a homework assignment for my CS java class, and I'm receiving the errors listed below. Below the second horizontal line is the source code. There is an additional java program file that's used to run Crypto.java called Lab13.java, and I don't quite understand the exception Logic. The code and my clarified question is at the bottom.
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
Here is the source code:
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();
}
}
So like I said, this next part is used to run Crypto. What exactly is it doing when it catches the IOException? Is it going to display the EOF exception error message because it's catching it from the try statement that executes Crypto.encryptFile?
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());
}
}
}