Seja bem vindo ao Fórum do JavaFree.org
Aqui você irá encontrar respostas para TUDO o que você precisa sobre java.
Deseja participar? Crie sua conta ou efetue seu login
Gostaria de saber como posso abrir um arquvi txt na tela usando java... Explicando melhor: ja existe um arquivo txt, queria q o programa abrisse ele na tela... como se eu fosse la e desse dois cliques nele....
Se você quer abrir o arquivo numa janela swing (puro java), uma maneira simples é ler todo o arquivo (new BufferedReader(new FileReader("arquivo"))) pra memória, transformando-o em uma String (StringBuffer), depois criar uma JFrame com uma JTextArea e jogar o texto nela. exemplo (não compilei):
Mas já se o que você quer fazer é abrir o arquivo usando o programa padrão do windows (normalmente o notepad), dê uma olhada no projeto JDIC, que lá eles têm uma API que permite esse tipo de coisa.
Tetsuo
_________________ In fact, people who study design methods without also practicing design are almost always frustrated designers who have no sap in them, who have lost, or never had, the urge to shape things. Such a person will never be able to say anything sensible about "how" to shape things either. (Christopher Alexander)
Amigão tentei executar seu codigo mas deu erro (usando eclipse)!
Aparece no console: java.lang.Error: Do not use javax.swing.JFrame.setLayout() use javax.swing.JFrame.getContentPane().setLayout() instead at javax.swing.JFrame.createRootPaneException(Unknown Source) at javax.swing.JFrame.setLayout(Unknown Source) at AnalisePreditiva.main(AnalisePreditiva.java:184)
Ah, tá, aquele código ia funcionar com o JDK 5. Pra versões anteriores, modifique a parte do JFrame pra isso:
_________________ In fact, people who study design methods without also practicing design are almost always frustrated designers who have no sap in them, who have lost, or never had, the urge to shape things. Such a person will never be able to say anything sensible about "how" to shape things either. (Christopher Alexander)
Anunciante
brunorisso Offline
Posts: 3
Gostaria de saber como posso abrir um arquvi txt na tela usando java...
Explicando melhor: ja existe um arquivo txt, queria q o programa abrisse ele na tela... como se eu fosse la e desse dois cliques nele....
ronaldtm Offline
Posts: 2299
Depende do que você quer.
Se você quer abrir o arquivo numa janela swing (puro java), uma maneira simples é ler todo o arquivo (new BufferedReader(new FileReader("arquivo"))) pra memória, transformando-o em uma String (StringBuffer), depois criar uma JFrame com uma JTextArea e jogar o texto nela. exemplo (não compilei):
Mas já se o que você quer fazer é abrir o arquivo usando o programa padrão do windows (normalmente o notepad), dê uma olhada no projeto JDIC, que lá eles têm uma API que permite esse tipo de coisa.
Tetsuo
_________________
In fact, people who study design methods without also practicing design are almost always frustrated designers who have no sap in them, who have lost, or never had, the urge to shape things. Such a person will never be able to say anything sensible about "how" to shape things either. (Christopher Alexander)
brunorisso Offline
Posts: 3
Amigão tentei executar seu codigo mas deu erro (usando eclipse)!
Aparece no console:
java.lang.Error: Do not use javax.swing.JFrame.setLayout() use javax.swing.JFrame.getContentPane().setLayout() instead
at javax.swing.JFrame.createRootPaneException(Unknown Source)
at javax.swing.JFrame.setLayout(Unknown Source)
at AnalisePreditiva.main(AnalisePreditiva.java:184)
Se puder me ajudar....
ronaldtm Offline
Posts: 2299
Ah, tá, aquele código ia funcionar com o JDK 5. Pra versões anteriores, modifique a parte do JFrame pra isso:
_________________
In fact, people who study design methods without also practicing design are almost always frustrated designers who have no sap in them, who have lost, or never had, the urge to shape things. Such a person will never be able to say anything sensible about "how" to shape things either. (Christopher Alexander)
Relacionados
Biblioteca de configurações http://javafree.uol.com.br/topic-852210-Biblioteca-de-configuracoes.html Exibição de texto com o foco do mouse http://javafree.uol.com.br/topic-851521-Exibicao-de-texto-com-o-foco-do-mouse.html Java2d - Funçao transformar um cor específica transparente http://javafree.uol.com.br/topic-857425-Java2d-Funcao-transformar-um-cor-especifica-transparente.html Ler um arquivo texto dentro de um jar http://javafree.uol.com.br/topic-859277-Ler-um-arquivo-texto-dentro-de-um-jar.html Ajuda para resolução de trabalho http://javafree.uol.com.br/topic-868019-Ajuda-para-resolucao-de-trabalho.html me ajudem: JTextArea http://javafree.uol.com.br/topic-865744-me-ajudem-JTextArea.html Synchronized http://javafree.uol.com.br/topic-869068-Synchronized.html arquivos - desafio http://javafree.uol.com.br/topic-859662-arquivos-desafio.html Alguém manja pular linha no XSL:Text http://javafree.uol.com.br/topic-5452-Alguem-manja-pular-linha-no-XSL-Text.html
Anunciante