查重

附件 : 查重.txt


package test;

import java.io.BufferedReader;
import java.io.File;
import java.io.FileInputStream;
import java.io.InputStreamReader;

public class test2 {
	public static String readFile(String path, String charset) {
		StringBuffer sb = new StringBuffer();
		try {
			File f = new File(path);
			InputStreamReader isr = new InputStreamReader(new FileInputStream(f), charset);
			BufferedReader br = new BufferedReader(isr);
			String line = null;
			while ((line = br.readLine()) != null) {
				sb.append(line);
			}
			isr.close();
		} catch (Exception e) {
			e.printStackTrace();
		}
		return sb.toString();
	}

	public static void main(String[] args) {
		String string = readFile("C:\\Users\\bumblebee\\Desktop\\查重.txt", "GBK");
		for (int i = 0; i < string.length() - 1; i++) {
			String temp = string.substring(i, i + 1);
			String end = string.substring(i + 1);
			if (!"".equals(temp) &&!" ".equals(temp) && !" ".equals(temp) && !",".equals(temp) && !"。".equals(temp) && end.contains(temp))
				System.out.print(temp);
		}

	}
}


运行结果

第一部分长藏分弟二部行调弹阿传核圈


赠人玫瑰 手留余香
初识IDEA
JAVA实现简单梅森素数算法
立即登录, 发表评论.
没有帐号? 立即注册
0 条评论