JAVA 读写文本+ 基本的文本处理(normalize)

package test.com;

import java.io.BufferedReader;
import java.io.File;
import java.io.FileInputStream;
import java.io.FileWriter;
import java.io.IOException;
import java.io.InputStreamReader;
import java.util.ArrayList;
import java.util.List;

public class normalization {
	public static void main(String[]args)throws Exception{
		File file = new File("C:\\Users\\xuchichi\\Desktop\\毕设新方法\\normalization\\SABToSymtomSim.txt");
		List<String> AllGene1 = readData1(file);
		List<String> AllGene2 = readData2(file);
		normalize2(AllGene1);
		//normalize2(AllGene1);
	}
	private static void normalize2(List<String> allGene) throws IOException {
		FileWriter writer = new FileWriter("C:\\Users\\xuchichi\\Desktop\\" +
				"毕设新方法\\normalization\\CountSimToSymtomSimResult.txt",true);
		double Max = -100;
		double Min = 100;
		for(int i =1;i<allGene.size();i++){
			double d = Double.valueOf(allGene.get(i)).doubleValue();
			if(d<Min)
				Min = d;
			if(d>Max)
				Max = d;
		}
		System.out.println(Max+" "+Min);
		writer.write(allGene.get(0)+"\n");
		for(int i=1;i<allGene.size();i++){
			double d = Double.valueOf(allGene.get(i)).doubleValue();
			d -= Min;
			d/=(Max-Min);
			d = 1-d;
			System.out.println(d);
			writer.write(d+"\n");
			writer.flush();
		}
		writer.close();
	}
	private static void normalize1(List<String> allGene) throws IOException {
		FileWriter writer = new FileWriter("C:\\Users\\xuchichi\\Desktop\\" +
				"毕设新方法\\normalization\\CountSimToSymtomSimResult.txt",true);
		double Max = -100;
		double Min = 100;
		for(int i =1;i<allGene.size();i++){
			double d = Double.valueOf(allGene.get(i)).doubleValue();
			if(d<Min)
				Min = d;
			if(d>Max)
				Max = d;
		}
		System.out.print(Max+" "+Min);
		writer.write(allGene.get(0)+"\n");
		for(int i=1;i<allGene.size();i++){
			double d = Double.valueOf(allGene.get(i)).doubleValue();
			d/=(Max-Min);
			System.out.println(d+" "+i);
			writer.write(d+"\n");
			writer.flush();
		}
		writer.close();
	}
	public static String[] cutString(String in) {
		return in.split("	");
	}
	public static List<String> readData1(File f) throws IOException {
		List<String> r = new ArrayList<String>();
		if (f.isFile() && f.exists()) {
			InputStreamReader reader = new InputStreamReader(
					new FileInputStream(f));
			BufferedReader bufferR = new BufferedReader(reader);
			// String GoTermId = null;
			String lineTxt = "";
			while ((lineTxt = bufferR.readLine()) != null) {
				String[] out = cutString(lineTxt);
				String in = out[0];
				r.add(in);
			}
		}
		return r;
	}
	
	public static List<String> readData2(File f) throws IOException {
		List<String> r = new ArrayList<String>();
		if (f.isFile() && f.exists()) {
			InputStreamReader reader = new InputStreamReader(
					new FileInputStream(f));
			BufferedReader bufferR = new BufferedReader(reader);
			// String GoTermId = null;
			String lineTxt = "";
			while ((lineTxt = bufferR.readLine()) != null) {
				String[] out = cutString(lineTxt);
				String in = out[1];
				r.add(in);
			}
		}
		return r;
	}
}

  • 0
    点赞
  • 2
    收藏
    觉得还不错? 一键收藏
  • 1
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论 1
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值