⭐ 欢迎来到虫虫下载站! | 📦 资源下载 📁 资源专辑 ℹ️ 关于我们
⭐ 虫虫下载站

📄 ioutil.java

📁 用java开发的关于
💻 JAVA
字号:
import java.io.File;
import java.io.RandomAccessFile;
import java.io.FileOutputStream;
import java.util.ArrayList;
import java.util.HashMap;


public class IOUtil {

	private String firstKeyValue;

	private String keyValue;

	private ArrayList keyValueList = new ArrayList();

	private WebsphereConfigure configure = new WebsphereConfigure();

	public IOUtil() {
		initCfgFile();
	}

	public void initCfgFile() {
		String configfile_path = configure.getConfigFilePath();
		String configfile_name = configure.getConfigFileName();
		try {
			File cfgFile = new File(configfile_path + configfile_name);
			RandomAccessFile randomFile = new RandomAccessFile(cfgFile, "r");
			firstKeyValue = randomFile.readLine();
			while (firstKeyValue.startsWith("#")) {
				firstKeyValue = randomFile.readLine();
				if (!firstKeyValue.startsWith("#"))
					break;
			}

			if (firstKeyValue != null) {
				keyValueList.add(firstKeyValue);
				keyValue = randomFile.readLine();
				while (keyValue != null) {
					keyValueList.add(keyValue);
					keyValue = randomFile.readLine();
				}
			}

		} catch (Exception e) {
			e.printStackTrace();
		}
	}

	public String getType() {
		String type = null;
		int begin = firstKeyValue.indexOf("type");
		int end = firstKeyValue.indexOf("CIID");
		String temp = firstKeyValue.substring(begin, end);
		int i = temp.trim().indexOf("=");
		type = temp.substring(i + 1).trim();
		return type;
	}

	public String getCIID(String asName, String type) {
		String ciid = null;
		String name = null;
		String type0 = null;
		String[] ciids = new String[keyValueList.size()];
		for (int i = 0; i < keyValueList.size(); i++) {

			ciids[i] = (String) keyValueList.get(i);
			// int begin=ciids[i].indexOf("name");
			int endName = ciids[i].indexOf("type");
			String tempName = ciids[i].substring(0, endName);
			int n = tempName.trim().indexOf("=");
			name = tempName.substring(n + 1).trim();

			int endType = ciids[i].indexOf("CIID");
			String tempType = ciids[i].substring(endName, endType);
			int m = tempType.trim().indexOf("=");
			type0 = tempType.substring(m + 1).trim();

			if (name.equals(asName)) {
				int endCIID = ciids[i].indexOf("cicat");
				String tempCIID = ciids[i].substring(endType, endCIID);
				int l = tempCIID.trim().indexOf("=");
				ciid = tempCIID.substring(l + 1).trim();
			}
		}
		return ciid;
	}

	public String getCICAT(String asName, String type) {
		String cicat = null;
		String name = null;
		String type0 = null;
		String[] cicats = new String[keyValueList.size()];
		for (int i = 0; i < keyValueList.size(); i++) {
			cicats[i] = (String) keyValueList.get(i);
			int endName = cicats[i].indexOf("type");
			String tempName = cicats[i].substring(0, endName);
			int n = tempName.trim().indexOf("=");
			name = tempName.substring(n + 1).trim();

			int endType = cicats[i].indexOf("CIID");
			String tempType = cicats[i].substring(endName, endType);
			int m = tempType.trim().indexOf("=");
			type0 = tempType.substring(m + 1).trim();

			if (name.equals(asName)) {
				int beginCicat = cicats[i].indexOf("cicat");
				int endCicat = cicats[i].indexOf("Is_part_of");
				String tempCicat = cicats[i].substring(beginCicat, endCicat);
				int l = tempCicat.trim().indexOf("=");
				cicat = tempCicat.substring(l + 1).trim();
			}
		}
		return cicat;
	}

	public String getIs_part_of(String asName, String type) {
		String is_part_of = null;
		String name = null;
		String type0 = null;
		String[] is_part_ofs = new String[keyValueList.size()];
		for (int i = 0; i < keyValueList.size(); i++) {
			is_part_ofs[i] = (String) keyValueList.get(i);
			int endName = is_part_ofs[i].indexOf("type");
			String tempName = is_part_ofs[i].substring(0, endName);
			int n = tempName.trim().indexOf("=");
			name = tempName.substring(n + 1).trim();

			int endType = is_part_ofs[i].indexOf("CIID");
			String tempType = is_part_ofs[i].substring(endName, endType);
			int m = tempType.trim().indexOf("=");
			type0 = tempType.substring(m + 1).trim();

			if (name.equals(asName)) {
				int beginIs_part_of = is_part_ofs[i].indexOf("Is_part_of");
				int endIs_part_of = is_part_ofs[i].indexOf("uses");
				String tempCicat = is_part_ofs[i].substring(beginIs_part_of,
						endIs_part_of);
				int l = tempCicat.trim().indexOf("=");
				is_part_of = tempCicat.substring(l + 1).trim();
			}
		}
		return is_part_of;
	}

	public String getUses(String asName, String type) {
		String uses = null;
		String name = null;
		String type0 = null;
		String[] usess = new String[keyValueList.size()];
		for (int i = 0; i < keyValueList.size(); i++) {
			usess[i] = (String) keyValueList.get(i);
			int endName = usess[i].indexOf("type");
			String tempName = usess[i].substring(0, endName);
			int n = tempName.trim().indexOf("=");
			name = tempName.substring(n + 1).trim();

			int endType = usess[i].indexOf("CIID");
			String tempType = usess[i].substring(endName, endType);
			int m = tempType.trim().indexOf("=");
			type0 = tempType.substring(m + 1).trim();

			if (name.equals(asName) ) {
				int beginUses = usess[i].indexOf("uses");
				// int endUses=usess[i].indexOf("uses");
				String tempCicat = usess[i].substring(beginUses);
				int l = tempCicat.trim().indexOf("=");
				uses = tempCicat.substring(l + 1).trim();
			}
		}
		return uses;
	}

	public void writeInNewFile(String path, String content) {
		try {
			File file = new File(path);
			FileOutputStream out = new FileOutputStream(file);
			out.write(content.getBytes());
			out.close();
		} catch (Exception e) {
			e.printStackTrace();
		}
	}

	public boolean checkOriginalFile(String origFileName) {
		boolean exist = false;
		try {
			File file = new File(origFileName);
			if (file.exists() && file != null) {
				exist = true;
			}
		} catch (Exception e) {
			e.printStackTrace();
		}
		return exist;
	}

	public HashMap getOrigFile(String origFileName) {
		File origFile = new File(origFileName);
		HashMap map = new HashMap();
		try {
			RandomAccessFile randomFile = new RandomAccessFile(origFile, "r");
			ArrayList orig = new ArrayList();
			String line = randomFile.readLine();
			while (line != null) {
				orig.add(line);
				line = randomFile.readLine();
			}
			String[] lines = new String[orig.size()];
			for (int i = 0; i < orig.size(); i++) {
				lines[i] = (String) orig.get(i);
				// keyValues=lines[i].split("=");
				int index = lines[i].indexOf("=");
				String key = lines[i].substring(0, index);
				String value = lines[i].substring(index + 1);
				map.put(key.trim(), value.trim());
			}
		} catch (Exception e) {
			e.printStackTrace();
		}
		return map;
	}
	public String getCIName(String globalFileName){
		String ci=null;
		File globalFile=new File(globalFileName);
		try{
			RandomAccessFile randomFile = new RandomAccessFile(globalFile, "r");
			String line=randomFile.readLine();
			while(line!=null){
				if(line.startsWith("ci_num_websphere")){
					int index=line.indexOf("=");
					ci=line.substring(index+1);
					break;
				}
				line=randomFile.readLine();
			}
		}catch(Exception e){
			e.printStackTrace();
		}
		return ci;
	}
}

⌨️ 快捷键说明

复制代码 Ctrl + C
搜索代码 Ctrl + F
全屏模式 F11
切换主题 Ctrl + Shift + D
显示快捷键 ?
增大字号 Ctrl + =
减小字号 Ctrl + -