package p1;
import java.io.FileReader;
import java.io.FileWriter;
public class J_ReadTxt
{
private static final String LIUYONG = "柳永宋词.txt";
private static final String JINGZHUANG = "景庄婉约.txt";
public static void main ( String[] args )
{
char[] cs = new char[1];
int count = 0;
String result = "";
try
{
FileReader fr = new FileReader (LIUYONG);
while (-1 != fr.read (cs))
{
String temp = String.valueOf (cs);
result += temp;
int b = temp.codePointAt (0);
if (b > 127)
{
count += 2;
}
else
{
count++;
}
}
fr.close ();
System.out.println ("文档的字节数: " + count);
String temp = " " + result + " ";
System.out.println ("字符串“柳永”出现的次数: " + ( temp.split ("\u67f3\u6c38").length - 1 ));
result = result.replaceAll ("\u67f3\u6c38", "\u666f\u5e84");
FileWriter fw = new FileWriter (JINGZHUANG);
fw.write (result);
fw.flush ();
fw.close ();
}
catch (Exception e)
{
e.printStackTrace ();
}
}
}