oi pessoal, criei um metodo fatiador, um metodo leitor() e um metodo salvar
o metodo ler() é chamado dentro de salvar()
e o metodo part() fatia a String content que tambem está em salvar()
o que ocorre é que se cria o arquivo xls porém o arquivo txt chamado("paulo;pinto;ferreira")
nao é fatiado em celulas diferentes, pior: da null!!
peço ajuda
grande abraço
1. import java.awt.Font;
2. import java.io.BufferedReader;
3. import java.io.BufferedWriter;
4. import java.io.File;
5. import java.io.FileReader;
6. import java.io.FileWriter;
7. import java.io.IOException;
8. import javax.swing.JFileChooser;
9.
10.
11. public class C1{
12.
13. File f;
14. String ler;
15.
16.
17. //METODO FATIADOR
18. public String part(String a){
19. String[]b = a.split(";");
20. for(int x =0;x <=4; x++){
21. System.out.println(b[x].toString());
22. }
23. return a;
24. }
25.
26.
27.
28. //LE ARQUIVO TXT
29. public String ler(){
30. JFileChooser choo = new JFileChooser();
31. int res = choo.showOpenDialog(choo);
32. if(res == JFileChooser.APPROVE_OPTION){
33. f = choo.getSelectedFile();
34. }
35. try{
36. BufferedReader l = new BufferedReader(new FileReader(f));
37. while(l.readLine() != null){
38. ler = l.readLine();
39. System.out.println(ler);
40. }
41. }
42. catch(Exception e){
43. e.printStackTrace();
44. }
45. return ler;
46. }
47.
48.
49.
50.
51.
52. //SALVA EM ARQUIVO XLS
53. public void salvar(){
54. String l = ler();
55.
56. JFileChooser choo = new JFileChooser();
57.
58. int res = choo.showSaveDialog(choo);
59. if(res == JFileChooser.APPROVE_OPTION){
60. f = choo.getSelectedFile();
61.
62. String novo = f.getAbsolutePath().concat(".xls");
63. String content = part(l); // USANDO METODO FATIADOR
64. File fileN = new File(novo);
65. try{
66. FileWriter ff = new FileWriter(fileN);
67. ff.append(content);
68. ff.close();
69. }
70. catch(IOException e){}
71. }
72.
73.
74. }
75.
76. public static void main(String[] args){
77. C1 C = new C1();
78. C.salvar();
79. }
80. }