62,634
社区成员




public static void main(String[] args) {
BufferedReader reader = null;
try {
reader = new BufferedReader(new FileReader("D:\\workspace\\test\\src\\test.txt"));
List<String> lines = new ArrayList<String>();
while(true){
String line = reader.readLine();
if(line == null){
break;
}else if(line.matches("\\s*")){
continue;
}else{
if(lines.indexOf(line) == -1){
lines.add(line);
}
}
}
for(int i = 0; i < lines.size(); i++){
System.out.println(lines.get(i));
}
} catch (FileNotFoundException e) {
e.printStackTrace();
} catch (IOException e) {
e.printStackTrace();
} finally{
if(reader != null){
try {
reader.close();
} catch (IOException e) {
e.printStackTrace();
}
}
}
}
public static void main(String[] args) {
BufferedReader reader = null;
try {
reader = new BufferedReader(new FileReader("D:\\workspace\\test\\src\\test.txt"));
Set set = new TreeSet();
while(true){
String line = reader.readLine();
if(line == null){
break;
}else if(line.matches("\\s*")){
continue;
}else{
set.add(line);
}
}
Iterator iterator = set.iterator();
while(iterator.hasNext()){
System.out.println(iterator.next());
}
} catch (FileNotFoundException e) {
e.printStackTrace();
} catch (IOException e) {
e.printStackTrace();
} finally{
if(reader != null){
try {
reader.close();
} catch (IOException e) {
e.printStackTrace();
}
}
}
}
FileInputStream fis=null;
InputStreamReader isr=null;
BufferedReader br=null;
String ss="";
String ssd="";
try {
fis=new FileInputStream("E:/a.txt");
br=new BufferedReader(new InputStreamReader(fis));
String str=null;
Set set=new LinkedHashSet();
try {
while((str=br.readLine())!=null)
{
char ch[]=str.toCharArray();
if(ch[0]!=ch[ch.length-1])
{
for(int i=0;i<ch.length;i++)
{
ss=ch[i]+"";
set.add(ss);
}
}
}
Iterator it =set.iterator();
while(it.hasNext())
{
ssd+=it.next();
}
System.out.print(ssd);
} catch (IOException e) {
// TODO Auto-generated catch block
e.printStackTrace();
}
} catch (FileNotFoundException e) {
// TODO Auto-generated catch block
e.printStackTrace();
}