Java io

1 resposta
M

Ba será que alguem pode me ajudar…estou escrevendo em um arquivo texto e preciso que a cada inserção pule uma linha no arquivo…que cada registro fique em uma ordem seguencial…se alguem puder me ajudar…

1 Resposta

W

Seguinte … da uma olhada ae no código …

public class CreateAndAddVar extends CheckExistFile {

	public void addContent (String fileName,String content){
			
			if(fileExist(fileName)){		//Verifica se o arquivo existe
				try{	
					BufferedWriter out = new BufferedWriter(new FileWriter(fileName, true));
					out.write("\n"+content);
					out.close();
				}
				catch (IOException e) {
					JOptionPane.showMessageDialog( null, "Não foi possível Completar a operação" ); //apresenta o conteudo			
				}
			}
			else{
				try {
					
				boolean temp = new File(fileName).createNewFile();
					BufferedWriter out = new BufferedWriter(new FileWriter(fileName, true));
					out.write(content);
					out.close();
	
				} 
		
				catch (IOException e) {
					System.out.println("!!Erro!!");
				}				
					
			}
			
	}
		

}
// fileSupport
public class CheckExistFile {

	public boolean fileExist(String fileName){
	
		boolean exists = (new File(fileName)).exists();
		if (exists)return true;
		else return false;

	}

}
Criado 11 de agosto de 2005
Ultima resposta 13 de ago. de 2005
Respostas 1
Participantes 2