Criar arquivos a partir de outros!

fala galera tudo bom!!

preciso de uma ajuda para fazer este trabalho aqui, e um sistema de nfe, mas este que estou fazendo e pra altomatizar o processo de envio de lote de rps, jah olhei em um topico sobre isso mas nao encontrei nada semelhante com o que eu tenho que fazer, caso alguem tenha visto ou jah tenha feito por favor me mandem um email no :
gabrielluismartins@gmail.com.

obrigado.

eu tenho um codigo aqui que ele tem o seguinte intuito:

  • eu preciso que este codigo pegue informações de dois arquivos, trechos diferentes e grave em um arquivo diferente, sendo que este arquivos e um xml.
    ateh a parte dele ser um xml eu posso estar vendo mais afrente, pq no momento o maior prob e este de juntar os arq.

vou postar o codigo e gostaria se possivel vcs me ajudassem com isto, ateh mesmo vendo se a melhorias.

        /*neste ponto eu tenho dois trechos 
        que leem os arquivos, tendo a leitura 
        dos arquivos eu quero pegar trechos 
         pequenos de cada texto e jogar 
         no arquivo abaixo*/
        
        
    //create file object

File file1 = new File("ident20100315.nfe");
File file2 = new File("15032010.rpt");
// caracter
int ch;

// Memoria de conteudo

StringBuffer strContent1 = new StringBuffer("");
StringBuffer strContent2 = new StringBuffer("");

FileInputStream fin1= null;
FileInputStream fin2 = null;
 
//Tenta abrir
try

{
 
fin1 = new FileInputStream(file1);
 
while( (ch = fin1.read()) != -1)

strContent1.append((char)ch);

fin1.close();
 }

catch(FileNotFoundException e)

{

System.out.println("Não acho no caminho " + file1.getAbsolutePath());
 
}

catch(IOException ioe)

{

System.out.println("Erro na abertura " + ioe);

}

try

{
 
fin2 = new FileInputStream(file2);
 
while( (ch = fin2.read()) != -1)

strContent2.append((char)ch);

fin2.close();
 }

catch(FileNotFoundException e)

{

System.out.println("Não acho no caminho " + file2.getAbsolutePath());
 
}

catch(IOException ioe)

{

System.out.println("Erro na abertura " + ioe);

}

if((strContent1 != null)&&(strContent2 != null)){
    System.out.println("File contents :");

System.out.println();
System.out.println(strContent1);

}
/* neste ponto eu preciso gravar os trechos
 adiquiridos dos dois arq de cima, 
 é aqui que eu travo*/
try {    
         // Gravando no arquivo    
         File arquivo;    
    
         arquivo = new File("arquivo.txt");    
         FileOutputStream fos = new FileOutputStream(arquivo);    
         String texto = "quero gravar este texto no arquivo";    //aqui viria o trecho que me traria os textos de lah de cima!!
         fos.write(texto.getBytes());    
         texto = "\nquero gravar este texto AQUI TAMBEM";    //idem acima
         fos.write(texto.getBytes());    
         fos.close();    
    
         // Lendo do arquivo    
         arquivo = new File("arquivo.txt");    
         FileInputStream fis = new FileInputStream(arquivo);    
    
         int ln;    
         while ( (ln = fis.read()) != -1 ) {    
            System.out.print( (char)ln );    
         }    
    
         fis.close();    
      }    
      catch (Exception ee) {    
         ee.printStackTrace();    
      }    
}

}

desde jah agradeço a sua ajuda.

alguem???

puxa vida ninguem quer me dar um helps!!!:slight_smile:

ai dei um update no cod mas continua com erro:

 public static void main(String[] args) {

        Date nom = new Date();
 SimpleDateFormat formato = new SimpleDateFormat("yyyyMMdd");
 String data = formato.format(nom);


File file1 = new File("ident"+ data +".nfe");
File file2 = new File(data +".rpt");
// caracter
int ch;

// Memoria de conteudo

StringBuffer strContent1 = new StringBuffer("");
StringBuffer strContent2 = new StringBuffer("");

FileInputStream fin1= null;
FileInputStream fin2 = null;

    //Tenta abrir
try

{

fin1 = new FileInputStream(file1);

while( (ch = fin1.read()) != -1)

strContent1.append((char)ch);

fin1.close();
 }

catch(FileNotFoundException e)

{

System.out.println("Não acho no caminho " + file1.getAbsolutePath());

}

catch(IOException ioe)

{

System.out.println("Erro na abertura " + ioe);

}

try

{

fin2 = new FileInputStream(file2);

while( (ch = fin2.read()) != -1)

strContent2.append((char)ch);

fin2.close();
 }

catch(FileNotFoundException e)

{

System.out.println("Não acho no caminho " + file2.getAbsolutePath());

}

catch(IOException ioe)

{

System.out.println("Erro na abertura " + ioe);

}
//abre o arquivo que desejo
    String startFile = new String(strContent1);
    String outFile = "rptA.xml";

    //criando as tags xml
    try {
        CSVReader reader = new CSVReader(new FileReader(startFile));
        String[] line = null;
        String[] header = reader.readNext();
        List out = new ArrayList();

        while((line = reader.readNext())!=null){
                List<String[]> item = new ArrayList<String[]>();
                for (int i = 0; i < header.length; i++) {
                        String[] keyVal = new String[2];
                        String string = header[i];
                        String val = line[i];
                        keyVal[0] = string;
                        keyVal[1] = val;
                        item.add(keyVal);
                }
                out.add(item);
        }
        //criando xml
        XStream xstream = new XStream();
        xstream.toXML(out, new FileWriter(outFile,false));
    }
    //caso nao ache o arquivo
    catch (Exception e) {
        // TODO Auto-generated catch block
        e.printStackTrace();
    }
    }

}

os erros que aparecem sao assim:

java.io.FileNotFoundException: 2010.03.15 00:09:27 N 0 368337 59 29,0

at java.io.FileInputStream.open(Native Method)
at java.io.FileInputStream.(FileInputStream.java:106)
at java.io.FileInputStream.(FileInputStream.java:66)
at java.io.FileReader.(FileReader.java:41)
at desenvolvimento1.Main.main(Main.java:98)

este codigo e para mandar a nfe via xml, soh que altomaticamente!! eu sei que tem foruns aqui sobre isto mas eu jah olhei e nao encontrei o que precisava, se alguem jah viu no forum por favor me mande o link pra eu analizar com base nisso!!!

alguem jah teve que fazer algo assim??? eu preciso terminar este sist.!!!, me ajudem por favor!!!

ah! so pra constar, estah e a primeira parte que preciso fazer, ou seja no momento eu naum preciso enviar o arquivo mas sim cria-lo primeiramente!!!