Hello,
I Have written this code in Java Swing, to convert XML-file to Text-file, but I get just an empty text file, why? could you please help me with that!! it is very urgent !!!!!!!!!!!!!!
import javax.swing.*;
import java.io.*;
import java.util.*;
import java.awt.*;
public class Convert {
public static void main(String[] arg) throws IOException{
String filnamn = JOptionPane.showInputDialo
g("Vad heter filen som skall läsas?");
//Skapa en ström från filen
BufferedReader inström = new BufferedReader(new FileReader(filnamn));
String filnamn2 = JOptionPane.showInputDialo
g("Vad heter filen som skall skrivas?");
PrintWriter utström = new PrintWriter(new BufferedWriter
(new FileWriter(filnamn2)));
int radNr = 0;
int i = 0;
//Läs filen
while (true){
String rad = inström.readLine();
if (rad == null)
break; //end of file
radNr ++;
utström.println(rad);
}
JOptionPane.showMessageDia
log(null, "kopiering är klar");
utström.close();
// System.out.flush();
Scanner sc = new Scanner(System.in);
JOptionPane.showInputDialo
g("Vad heter filen som ska ändras till text fil?");
System.out.flush();
String namn = sc.next();
//Öppna filen
BufferedReader inFil = new BufferedReader(new FileReader(namn));
//Läs filen och skriv det.
String rad = inFil.readLine();
for (radNr = 0; i < rad.length(); radNr++){
while ((i = inFil.read()) != -1){
char c = (char) i;
switch(c) {
case '<':
if ( c == '<')
System.out.print('\u0020')
; //
else {
System.out.print(c); //inström.skip(60); //}
}
break;
case '>':
if ( c == '>')
System.out.print('\u0020')
;
else {
System.out.print(c);
}
break;
case '?':
if ( c == '?')
System.out.print('\u0020')
;
else { System.out.print(c); }
break;
case '/':
if ( c == '/')
System.out.print('\u0020')
;
else { System.out.print(c); }
break;
case '}':
if ( c == '}')
System.out.print('\u0020')
;
else { System.out.print(c); }
break;
case '{':
if ( c == '{')
System.out.print('\u0020')
; //utström.print(' ');
else {
System.out.print(c); }
break;
default:
radNr++;
}
}
}
System.out.print(" ");
System.out.flush();
}
Best Regards
Fifian
Start Free Trial