I keep getting a FileCopySift class error or something and i justu
can't figure it any assistantce would be greatly appreciated.
import java.io.*;
public class FileCopySift
{
public static void main(String args[])
{
if (args.length != 3)
{
System.err.println("How to use correct syntax with this
program:");
System.err.println("java FileCopySift <source file>
<destination> <filter>");
}
else
try
{
copy(args[0], args[1], args[2]);
}
catch(IOException ioexception)
{
System.err.println(ioexception.getMessage());
}
}
public static void copy(String one, String two, String three)
throws IOException
{
File file1 = new File(one);
File file2 = new File(two);
if(!file1.exists())
abort("ERROR: no such source file: " + one);
if(!file1.isFile())
abort("ERROR: can't copy directory: " + one);
if(!file1.canRead())
abort("ERROR: source file is unreadable: " + one);
if(file2.isDirectory())
file2 = new File(file1, file1.getName());
if(file2.exists())
{
if(!file2.canWrite())
abort("ERROR: destination file is unwriteable: " +
two);
System.out.print("Overwrite existing file " + two + "?
(Y/N): ");
System.out.flush();
BufferedReader bufferedreader = new BufferedReader(new
InputStreamReader(System.in));
String five = bufferedreader.readLine();
if(!five.equals("Y") && !five.equals("y"))
abort("ERROR: existing file was not overwritten.");
} else
{
String four = file1.getParent();
if(four == null)
four = System.getProperty("user.dir");
File file3 = new File(four);
if(!file3.exists())
abort("ERROR: destination directory doesn't exist: "
+ four);
if(file3.isFile())
abort("ERROR: destination is not a directory: " +
four);
if(!file3.canWrite())
abort("ERROR: destination directory is unwriteable: "
+ four);
}
FileReader filereader = null;
FileWriter filewriter = null;
try
{
filereader = new FileReader(file1);
filewriter = new FileWriter(file2);
BufferedReader bufferedreader1 = new BufferedReader
(filereader);
PrintWriter printwriter = new PrintWriter(filewriter);
String six = bufferedreader1.readLine();
for(; six != null; six = bufferedreader1.readLine())
{
StringBuffer stringbuff1 = new StringBuffer(six);
StringBuffer stringbuff2 = new StringBuffer();
stringbuff2.setLength(six.length());
if(six.indexOf(three) != -1)
{
int i = 0;
int j = 0;
while(i < stringbuff1.length())
if(stringbuff1.charAt(i) == '<')
{
for(; i < stringbuff1.length() &&
stringbuff1.charAt(i) != '>'; i++);
i++;
} else
{
stringbuff2.setCharAt(j,
stringbuff1.charAt(i));
i++;
j++;
}
six = stringbuff2.toString();
printwriter.println(six);
}
}
}
finally
{
if(filereader != null)
try
{
filereader.close();
}
catch(IOException ioexception) { }
if(filewriter != null)
try
{
filewriter.close();
}
catch(IOException ioexception1) { }
}
}
private static void abort(String one) throws IOException
{
throw new IOException(one);
}
}