Problema com manipulação de arquivos

0 respostas
GabrielCardelli

Falae galera beleza? O programa ta dificil de compreender pôs é meu primeiro programa com issoo... nao to conseguindo resolver o erro a saida ta errada =/

se alguem poder me ajudar... obrigado

O erro é que eu escrevo as faixas do cd... quando eu vou executar eu quero que troque tudo que tem Gabriel por FELIPE.. ai ta o erro.. =/

Obrigado desde já.

CD

import java.io.BufferedWriter;
import java.io.FileNotFoundException;
import java.io.FileOutputStream;
import java.io.IOException;
import java.io.OutputStream;
import java.io.OutputStreamWriter;
import java.util.Scanner;


public class CD{
	
	public BufferedWriter criararq() throws Exception
	{
		OutputStream os = new FileOutputStream("myCd.mYeXt");
		OutputStreamWriter osw = new OutputStreamWriter(os);
		BufferedWriter bw = new BufferedWriter(osw);
		return bw;	
	}
	
	public void addFaixa(String faixa, BufferedWriter bw,boolean a) throws IOException
	{
		if (a == true)
		{
		bw.close();
		System.exit(1);
		}
		
		
		Scanner entrada = new Scanner(System.in);
		
		String args = faixa;
		
		bw.newLine();
		bw.write(args);
		bw.newLine();
		
		
		
	}

}

TESTECD

import java.io.BufferedReader;
import java.io.BufferedWriter;
import java.io.FileInputStream;
import java.io.IOException;
import java.io.InputStream;
import java.io.InputStreamReader;
import java.util.Scanner;

public class TesteCD {

	public static void main(String[] args) throws Exception {
		Scanner entrada = new Scanner(System.in);

		System.out
				.println("O QUE DESEJA FAZER>>> \n 1. ESCREVER NOVO ARQUIVO \n 2. GUARDAR ARQUIVO NUM ARRAY");
		int opa = entrada.nextInt();

		if (opa == 1) {
			CD c01 = new CD();

			BufferedWriter a = c01.criararq();
			boolean ok = true;
			int cont = 1;

			while (ok) {
				System.out.println("Dig. o nome da faixa: ");
				String nom = entrada.nextLine();
				System.out.println("Dig. o nome do cantor: ");
				String nomc = entrada.nextLine();

				String conca = "Musica: " + nom + " - Cantor:  " + nomc;
				c01.addFaixa(conca, a, false);

				System.out.println("Quer digitar outro? ");
				String op = entrada.nextLine();
				if (op.equals("Nao")) {
					c01.addFaixa(nom, a, true);
				}
				cont++;
			}
		} else if (opa == 2) {
			InputStream is = new FileInputStream("myCd.mYeXt");// começa aki
			InputStreamReader isr = new InputStreamReader(is);
			BufferedReader br = new BufferedReader(isr);

			String s = br.readLine();
			String[] array = new String[30];
			int cont = 0;
			while (s != null) {

				s = br.readLine();
				array[cont] = s;
				cont++;

			}

			String[] aux = new String[20];
try{
			for (int a = 0; a < array.length; a++) {
				System.out.println(array[a]);
				String[] p = array[a].split(":");

				for (int b = 0; b < p.length; b++) {
					if (p[b].contains("Gabriel")) {
						p[b] = "FELIPE";

					}
				}
				array[a] = "";
				for (int c = 0; c < p.length; c++) {
					try{
					array[a] += " " + p[c];
					}catch(NullPointerException e){}
				}
				System.out.println("\n" + array[a] + "\n");
			}
	}catch(NullPointerException a){}

		}

	}

}
Criado 11 de abril de 2009
Respostas 0
Participantes 1