难以编译此代码。由于新文件中定义的“目标”,因此从第75行获得了找不到符号错误。我本来以为它与dest字符串末尾指定的路径有关,但是编辑似乎无济于事。我在代码的前面缺少什么吗?任何帮助表示赞赏。
import java.io.BufferedReader;
import java.io.BufferedWriter;
import java.io.File;
import java.io.FileInputStream;
import java.io.FileNotFoundException;
import java.io.FileWriter;
import java.io.IOException;
import java.io.InputStreamReader;
import java.io.PrintWriter;
import java.io.RandomAccessFile;
public class FileReader_Writer {
public static void parseData(File fin, File fout) throws IOException{
FileInputStream fis = new FileInputStream(fin);
BufferedReader in = new BufferedReader(new InputStreamReader(fis));
FileWriter fstream = new FileWriter(fout, true);
PrintWriter pOut = new PrintWriter(fstream, true);
BufferedWriter out = new BufferedWriter(fstream);
int totalChar = 0;
String aLine = null;
int line =0;
while ((aLine = in.readLine()) != null) {
int linelength = aLine.length();
totalChar = totalChar + linelength;
}
while ((aLine = in.readLine()) != null) {
int linelength = aLine.length();
totalChar = totalChar + linelength;
pOut.printf("%10s %-1s\n",linelength,aLine);
String newLine =System.getProperty("line.separator");
pOut.write(newLine);
}
RandomAccessFile f = new RandomAccessFile(new File(dest), "rw");
f.getChannel().position(0);
f.writeChars("File contains "+totalChar+ "Characters ");
in.close();
out.close();
}
public static void main(String[] args) throws IOException {
String source = "C:/Users/Admin/in.txt";
String dest = "C:/Users/Admin/out.txt";
File fin = new File(source);
File fout = new File(dest);
parseData(fin, fout);
}
}