关于泛型!
import java.io.*;import java.util.*;
public class TextFile extends ArrayList
{
public static String read(String fileName) throws IOException
{
StringBuffer sb=new StringBuffer();
BufferedReader in=new BufferedReader(new FileReader(fileName));
String s;
while((s=in.readLine())!=null)
{
sb.append(s);
sb.append("\n");
}
in.close();
return sb.toString();
}
public static void write(String fileName,String text) throws IOException
{
PrintWriter out=new PrintWriter(new BufferedWriter(new FileWriter(fileName)));
out.print(text);
out.close();
}
public TextFile(String fileName) throws IOException
{
super(Arrays.asList(read(fileName).split("\n")));
}
public void write(String fileName) throws IOException
{
PrintWriter out=new PrintWriter(new BufferedWriter(new FileWriter(fileName)));
for(int i=0;i<size();i++)
out.println(get(i));
out.close();
}
public static void main(String[] args) throws Exception
{
String f=read("TextFile.java");
write("test.txt",f);
TextFile text=new TextFile("test.txt");
text.write("test2.txt");
}
}
编译不通过..
请帮忙看下,解释一下..
谢谢帮忙.