Ped@ntilva Posted April 7, 2006 at 01:08 PM Report #21289 Posted April 7, 2006 at 01:08 PM Boas pessoal, Eu estou a fazer uma pequena aplicação que funciona tipo um explorer. O meu problema é: Como é que faço para abrir um ficheiro que o utilizador selecionou? Ou seja: O utilizador seleciona o ficheiro que pretende de uma lista de ficheiros e quero que entre nesse ficheiro. Será que alguem me sabe dizer como posso fazer isso? Cumps, Pedantilva
Dabubble Posted April 7, 2006 at 02:34 PM Report #21299 Posted April 7, 2006 at 02:34 PM String filePath = "C:\myFiles\FileXPTO.txt"; File file = new File(filePath ); try { BufferedReader br = new BufferedReader(new FileReader(file)); String theLine = null; // imprime o conteudo do ficheiro linha a linha while ((theLine = br.readLine()) != null){ System.out.println(theLine); } } catch (FileNotFoundException e) { e.printStackTrace(); //To change body of catch statement use File | Settings | File Templates. } catch (IOException e) { e.printStackTrace(); //To change body of catch statement use File | Settings | File Templates. }
Ped@ntilva Posted April 7, 2006 at 09:39 PM Author Report #21358 Posted April 7, 2006 at 09:39 PM Thks. Isso funciona. Mas só para txt. Se eu tentar entrar noutro tipo de ficheiro da uns caracteres esquisitos.... Não existe outra forma? Cumps.
Dabubble Posted April 8, 2006 at 01:11 PM Report #21384 Posted April 8, 2006 at 01:11 PM Isso tem a haver com o encoding do ficheiro. Vou ver se da para mudar o encoding no reader... depois digo kk koisa.
freesumo Posted April 10, 2006 at 06:32 PM Report #21593 Posted April 10, 2006 at 06:32 PM ? Ped@ntilva explica melhor o que queres fazer...
Ped@ntilva Posted April 11, 2006 at 12:34 PM Author Report #21660 Posted April 11, 2006 at 12:34 PM OK, eu tento explicar melhor. Quando estás em ambiente Windows entras no explorer do windows e aparece ficheiros e pastas. Quando clicas duas vezes nas pastas o explorador abre essas pastas. E quando clicas duas vezes nos ficheiros eles abrem. A parte das pastas já fiz. É simples. Agora o que eu quero é que abra o ficheiro como se fosse no explorador do windows. O que o Dabubble disse é para ler o ficheiro linha a linha mas o que eu quero é que abra esse ficheiro sem ser atraves do java. Percebes-te? Cumps.
Dabubble Posted April 11, 2006 at 02:28 PM Report #21684 Posted April 11, 2006 at 02:28 PM explicaste mal o que querias... O que tu queres e por o java a executar programas neh tipo correr exe's etc? isso e toda uma outra historia mas tambem da para fazer. nao sei e exactamente como...
freesumo Posted April 19, 2006 at 07:24 AM Report #22803 Posted April 19, 2006 at 07:24 AM Ped@ntival já sabes como se faz? Quando souberes diz qualquer coisa. 🙂
Ped@ntilva Posted April 19, 2006 at 12:54 PM Author Report #22826 Posted April 19, 2006 at 12:54 PM N. ainda n sei. Cumps.
Dabubble Posted April 19, 2006 at 02:09 PM Report #22842 Posted April 19, 2006 at 02:09 PM Para executar programas exteriores em java (tipo um exe kk) o comando e: Runtime.getRuntime.exec("ocaminhoparaomeufile/omeufile.exe");
Ped@ntilva Posted April 19, 2006 at 09:30 PM Author Report #23012 Posted April 19, 2006 at 09:30 PM Isso não me está a funcionar. Tenho que fazer o import java.lang.Runtime; Certo? Mas mesmo assim não dá.
ouvi_dizer Posted April 20, 2006 at 12:32 PM Report #23082 Posted April 20, 2006 at 12:32 PM Qual é a excepção?
ouvi_dizer Posted April 20, 2006 at 12:35 PM Report #23083 Posted April 20, 2006 at 12:35 PM try{ Runtime.getRuntime().exec("notepad.exe"); } catch(Exception e){ e.printStackTrace(); }
ouvi_dizer Posted April 20, 2006 at 12:43 PM Report #23085 Posted April 20, 2006 at 12:43 PM Agora li melhor a tua questão. Provávelmente este código por si só não te ajuda. Para saberes que tipo de ficheiro é e consequentemente saber que tipo de aplicação o lê tens que olhar para o mime type do ficheiro. Sobre mime types = http://mindprod.com/jgloss/mime.html
Recommended Posts
Create an account or sign in to comment
You need to be a member in order to leave a comment
Create an account
Sign up for a new account in our community. It's easy!
Register a new accountSign in
Already have an account? Sign in here.
Sign In Now