GUJ
Notícias, artigos e o maior fórum brasileiro sobre Java
home
fórum
notícias
tópicos recentes
empregos
artigos
Bem-vindo ao GUJ.
Crie seu login
, ou digite-o para logar no site.
Usuário:
Senha:
PrintWriter - Dúvida
Índice dos Fóruns
»
Java Básico
Autor
Mensagem
22/05/2007 16:15:51
Assunto:
PrintWriter - Dúvida
Daniel Ilha
JavaBaby
Membro desde: 23/06/2006 11:42:08
Mensagens: 79
Localização: Porto Alegre
Offline
1. Qual a diferença?
out = new PrintWriter(new FileWriter("teste.txt" ));
e
out = new PrintWriter("teste.txt");
Se ambas geram o arquivo "teste.txt".
Agradeço desde já!
22/05/2007 16:23:05
Assunto:
PrintWriter - Dúvida
Filipe Sabella
GUJ Expert
Membro desde: 12/03/2003 11:25:57
Mensagens: 4680
Offline
JavaDoc
/** * Creates a new PrintWriter, without automatic line flushing, with the * specified file name. This convenience constructor creates the necessary * intermediate {@link java.io.OutputStreamWriter OutputStreamWriter}, * which will encode characters using the {@linkplain * java.nio.charset.Charset#defaultCharset default charset} for this * instance of the Java virtual machine. * * @param fileName * The name of the file to use as the destination of this writer. * If the file exists then it will be truncated to zero size; * otherwise, a new file will be created. The output will be * written to the file and is buffered. * * @throws FileNotFoundException * If the given string does not denote an existing, writable * regular file and a new regular file of that name cannot be * created, or if some other error occurs while opening or * creating the file * * @throws SecurityException * If a security manager is present and {@link * SecurityManager#checkWrite checkWrite(fileName)} denies write * access to the file * * @since 1.5 */ public PrintWriter(String fileName) throws FileNotFoundException { this(new BufferedWriter(new OutputStreamWriter(new FileOutputStream(fileName))), false); }
Former LIPE.
22/05/2007 17:01:22
Assunto:
Re:PrintWriter - Dúvida
marcosbrandao
JavaEvangelist
Membro desde: 17/08/2006 19:03:36
Mensagens: 477
Offline
A unica diferença eh o argumento que tu passa para o construtor.
Um eh um FileWriter e o outro uma String.
De resto eh igual.
22/05/2007 19:20:17
Assunto:
Re:PrintWriter - Dúvida
LPJava
GUJ Hacker
Membro desde: 18/04/2006 12:50:23
Mensagens: 5524
Localização: Bahia/Porto Alegre
Offline
é o que marcos falou.. isso seria redudante.... ambos casos acima.. criar o arquivo e vc ja pode escrever nele..
Sun Certified Java Programmer 5.0
Blog:http://www.camilolopes.com
Twitter:www.twitter.com/camilolope
Linkedin:
http://br.linkedin.com/in/camilolopes
Curso online OCPJP:
http://pro.imasters.com.br/online/cursos/preparatorio-para-certificacao-java-ocjp
Autor livro Guia SCJP & JEE c/ Frameworks:
http://blog.camilolopes.com.br/livrosrevistaspalestras/
Índice dos Fóruns
»
Java Básico
Ir para:
Selecione um Fórum
Notícias
Assuntos gerais (Off-topic)
MundoJ - Artigos, Notícias e Debates
Artigos e Tutoriais
Java Básico
Java Avançado
Ferramentas, Frameworks e Utilitários
Desenvolvimento Web
Interface Gráfica
Google Android e Java Micro Edition (ME)
Certificação Java
Persistência: Hibernate, JPA, JDBC e outros
Java Enterprise Edition (Java EE)
Frameworks e Bibliotecas brasileiros
RIA - Flex, JavaFX e outros
Arquitetura de Sistemas
Metodologias de Desenvolvimento e Testes de Software
JavaScript
Ruby & Ruby on Rails
Outras Linguagens
Powered by
JForum 2.1.8
©
JForum Team