Cod sursa(job #1359938)

Utilizator RoxanaCptCapitanu Roxana - Steliana RoxanaCpt Data 25 februarie 2015 09:58:43
Problema Convertor Scor 60
Compilator java Status done
Runda rosedu_cdl_2015 Marime 2.06 kb
import java.io.*;
import java.util.*;
import org.omg.PortableInterceptor.SYSTEM_EXCEPTION;
/*
 * To change this license header, choose License Headers in Project Properties.
 * To change this template file, choose Tools | Templates
 * and open the template in the editor.
 */
   
/**
 *
 * @author Roxana Capitanu
 */
public class Main {
   
    /**
     * @param args the command line arguments
     */
    
    public static void main(String[] args) throws IOException {
         String allText = null, line;
       // String head;
        String list[];
       
   /*RandomAccessFile f = new RandomAccessFile("convertor.in", "r");
byte[] b = new byte[(int)f.length()];
f.read(b);*/
        File f = new File("convertor.in");

    byte[] buffer = new byte[(int)f.length()];
    FileInputStream is = new FileInputStream("convertor.in");
    is.read(buffer);
    is.close();

    allText = new String(buffer, "UTF-8");
         //BufferedReader br;
         //br = new BufferedReader(new FileReader("convertor.in"));
         BufferedWriter bw = new BufferedWriter(new FileWriter("convertor.out"));
        /* while ((line = br.readLine()) != null){
             allText += line;
              }
         */

         //allText = new String(b, "UTF-8");
          list = allText.split("}");
          //head = list[0];
          for (String s : list[0].split(","))
              bw.write(s.split(":")[0].split("\"")[1] + ",");
          bw.newLine();
          String[] aux;  
          for (String str : list){
            for (String s : str.split(",")){
                aux = s.split(":");
                if (aux.length > 1)
                {
                   if (aux[1].split("\"").length > 1)
                    bw.write(aux[1].split("\"")[1] + ",");
                     else
                     bw.write(aux[1].replaceAll(" ", "").replaceAll(",","") + ","); 
                }
            }      
                bw.newLine();
          } 
            //br.close();
            bw.close();
                
         
    }
       
}