📄 listwisedeletion.java
字号:
/* * $RCSfile: ListwiseDeletion.java,v $ * $Revision: 1.1 $ * $Date: 2005/04/17 00:38:41 $ * * NeuralNetworkToolkit * Copyright (C) 2004 Universidade de Bras�lia * * This file is part of NeuralNetworkToolkit. * * NeuralNetworkToolkit is free software; you can redistribute it and/or modify * it under the terms of the GNU General Public License as published by * the Free Software Foundation; either version 2 of the License, or * (at your option) any later version. * * NeuralNetworkToolkit is distributed in the hope that it will be useful, * but WITHOUT ANY WARRANTY; without even the implied warranty of * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the * GNU General Public License for more details. * * You should have received a copy of the GNU General Public License * along with NeuralNetworkToolkit; if not, write to the Free Software * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA - 02111-1307 - USA. */package neuralnetworktoolkit.preprocessor;import java.io.BufferedReader;import java.io.BufferedWriter;import java.io.File;import java.io.FileNotFoundException;import java.io.FileReader;import java.io.FileWriter;import java.io.IOException;import java.util.ResourceBundle;import neuralnetworktoolkit.datamanager.textfilemanager.LoadFromFileException;/** * @author <a href="mailto:hugoiver@yahoo.com.br">Hugo Iver V. Gon�alves</a> * @author <a href="mailto:rodbra@pop.com.br">Rodrigo C. M. Coimbra</a> */public class ListwiseDeletion { private ResourceBundle resources; /** Stores attributes names. */ private String[] dataHeader; /** * * @param file * @param separator * * @throws LoadFromFileException */ public void delete(File file, String separator, String missingSymbol) throws ListwiseDeletionException { String readedDataHeader; String dataLine; String newLine = new String(); String[] dataValues; File outputFile; FileReader inputReader; FileWriter fileWriter; BufferedReader inputBuffer; BufferedWriter writeBuffer; int size = 0; boolean hasMissing; try { //resources = ResourceBundle.getBundle("neuralnetworktoolkit.preprocessor.resources.Messages"); inputReader = new FileReader(file); outputFile = new File(file.getName() + "-listwiseD"); fileWriter = new FileWriter(outputFile); outputFile.createNewFile(); writeBuffer = new BufferedWriter(fileWriter); inputBuffer = new BufferedReader(inputReader); readedDataHeader = inputBuffer.readLine(); writeBuffer.write(readedDataHeader); writeBuffer.newLine(); dataHeader = readedDataHeader.split(separator); size = dataHeader.length; while(inputBuffer.ready()) { hasMissing = false; dataLine = inputBuffer.readLine(); dataValues = dataLine.split(separator); for (int i = 0; (i < size)&&(!hasMissing); i++) { if (missingSymbol.equals(dataValues[i])) { hasMissing = true; } } if (!hasMissing) { writeBuffer.write(dataLine); writeBuffer.newLine(); } } writeBuffer.close(); } catch(FileNotFoundException e) { throw new ListwiseDeletionException(resources.getString("fileNotFound") + " " + file.getName() + ".\n"); } catch(IOException e) { throw new ListwiseDeletionException(resources.getString("failToRead") +" " + file.getName() + ".\n"); } catch(NumberFormatException e) { throw new ListwiseDeletionException("Fail to read file " + file.getName() + ".\nThis is not a valid file!\n"); } } // delete() public void delete(String fileName, String separator, String missingSymbol) throws ListwiseDeletionException { delete(new File(fileName), separator, missingSymbol); } //delete()} //ListwiseDeletion
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -