Colegas,
Tenho uma aplicação em um pda que grava um arquivo.txt em uma pasta do servidor.
Existe uma forma de tão logo esse arquivo seja gravado eu executar uma classe?
Muito obrigado,
José Marques
Colegas,
Tenho uma aplicação em um pda que grava um arquivo.txt em uma pasta do servidor.
Existe uma forma de tão logo esse arquivo seja gravado eu executar uma classe?
Muito obrigado,
José Marques
Cria uma thread, essa thread vai ficar varrendo essa pasta de tempos em tempos, quando pingar uma arquivo .txt nela, a thread “executa a classe” como vc disse.
abraços!
Caro mcbarsotti,
Vc tem um exemplo de como criar essa thread?
Sou zerado em thread…
Abraços,
Marques
Cara, peguei uma classe que fiz a um tempo atraz para o projeto da NF-e, a thread fica varrendo a pasta esperando pingar um arquivo de tempos em tempos.
Tem outras coisas, mas oque vc precisa ta ai. da uma olhada, qq coisa te ajudo!
public class IniciaWebService implements Runnable {
private WebService webservice;
public IniciaWebService(WebService webservice){
this.webservice = webservice;
}
@Override
public void run() {
ArrayList<String> xmls = new ArrayList<String>();
File file = new File(webservice.getKeyLocalXML());
File[] files;
BufferedReader in = null;
StringBuffer buffer = null;
int numeroDeTentativas = 0;
while(true){
files = file.listFiles();
if(numeroDeTentativas == Configuracao.LIMITE_TENTATIVAS){
break;
}else if(files.length == 0){
try {
numeroDeTentativas++;
this.wait(Configuracao.TEMPO_PROXIMA_TENTATIVA);
} catch (InterruptedException e) {
e.printStackTrace();
}
}
for(File fileTemp : files){
buffer = new StringBuffer();
try {
in = new BufferedReader(new FileReader(fileTemp));
while(in.ready()){
buffer.append(in.readLine());
}
xmls.add(buffer.toString());
//TODO: COLOCAR VALOR EM PROPERTIES.
if(xmls.size() == Configuracao.BLOCO_LIMITE_XML_RECEPCAO || files.length < Configuracao.BLOCO_LIMITE_XML_RECEPCAO){
for(String xml : xmls){
webservice.iniciaWebService(xml);
}
xmls.clear();
}
} catch (FileNotFoundException e) {
e.printStackTrace();
} catch (IOException e) {
e.printStackTrace();
}
}
}
}
}
Abraços!