Problema para criar arquivo em JSP

3 respostas
P

Pessoal, meu JSP precisa criar um arquivo.csv no meu servidor: …/webapps/nome_aplicacao/temp/arquivo.csv

Com o cógigo abaixo eu consigo criar a pasta “temp”, mas o arquivo.csv eu nao consigo… o que está errado???

ServletContext ctx = getServletContext();
String path = ctx.getRealPath( "/" );

out.print("<br>PATH: " + path);
 
File diretorio = new File(path + "temp");
diretorio.mkdir(); 

String pathArquivo = path + "temp\\Relatorio.csv";

out.print("<br>PATH ARQUIVO: " + pathArquivo);

File arquivo = new File ( pathArquivo );				
FileWriter fw = new FileWriter( pathArquivo );
PrintWriter saida = new PrintWriter( fw, true );
saida.print(conteudo);
saida.close();
fw.close();

3 Respostas

rmarin

Tenta assim:

FileWriter fw = new FileWriter( arquivo );
        BufferedWriter bw = new BufferedWriter(fw);
        bw.write("String Desejada");
        bw.close();

:stuck_out_tongue:

dudaskank

não sei direito mas… e se trocar o path por isso?

String pathArquivo = path + "temp/Relatorio.csv";

flw

P

rmarin:
Tenta assim:

FileWriter fw = new FileWriter( arquivo );
        BufferedWriter bw = new BufferedWriter(fw);
        bw.write("String Desejada");
        bw.close();

:stuck_out_tongue:

Deu certo!!!
Muito obrigada!!!

Criado 26 de julho de 2006
Ultima resposta 26 de jul. de 2006
Respostas 3
Participantes 3