| 网站首页 | 业界新闻 | 小组 | 威客 | 人才 | 下载频道 | 博客 | 代码贴 | 在线编程 | 编程论坛
欢迎加入我们,一同切磋技术
用户名:   
 
密 码:  
共有 530 人关注过本帖
标题:关于泛型!
只看楼主 加入收藏
gioxiao
Rank: 1
等 级:新手上路
帖 子:35
专家分:0
注 册:2006-10-14
收藏
 问题点数:0 回复次数:1 
关于泛型!
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");
}
}
编译不通过..
请帮忙看下,解释一下..
谢谢帮忙.
搜索更多相关主题的帖子: 泛型 
2007-01-16 00:01
千里冰封
Rank: 16Rank: 16Rank: 16Rank: 16
来 自:灌水之王
等 级:版主
威 望:155
帖 子:28477
专家分:59
注 册:2006-2-26
收藏
得分:0 
[CODE]import java.io.*;
import java.util.*;
public class TextFile<E> extends ArrayList<E>
{
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(Collection<E> c) throws IOException
{
super(c);
}
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<String> text=new TextFile<String>(Arrays.<String>asList(read("test.txt").split("\n")));

text.write("test2.txt");
}
}[/CODE]

改成这样就不会有警告了

你的代码是可以编译通过的,只是有警告而已

可惜不是你,陪我到最后
2007-01-16 09:21
快速回复:关于泛型!
数据加载中...
 
   



关于我们 | 广告合作 | 编程中国 | 清除Cookies | TOP | 手机版

编程中国 版权所有,并保留所有权利。
Powered by Discuz, Processed in 0.019001 second(s), 8 queries.
Copyright©2004-2024, BCCN.NET, All Rights Reserved