Boa noite,
Eu criei dois projetos diferente, um que lista o que tem em um diretório e outro que renomeia os arquivos desse diretório e agora to tentando juntar eles, mas não está dando certo.
Alguém pode dar uma olhada no código e me ajudar achar o que está errado?
Servidor:
[code]import java.io.File;
import java.rmi.AlreadyBoundException;
import java.rmi.RemoteException;
import java.rmi.registry.LocateRegistry;
import java.rmi.registry.Registry;
import java.rmi.server.UnicastRemoteObject;
import java.sql.Connection;
import java.sql.DriverManager;
import java.sql.SQLException;
import java.sql.Statement;
/*
-
To change this template, choose Tools | Templates
-
and open the template in the editor.
/
/* -
@author Munique
*/
public class ServidorCompletoRMI implements InterfaceCompleta {private static String dir = “C:” + File.separator + “Users” + File.separator + “Munique” + File.separator + “Documents”
+ File.separator + “aleatorio” + File.separator + “series.txt”;
private static String dir2 = “C:” + File.separator + “Users” + File.separator + “Munique” + File.separator + “Documents”
+ File.separator + “aleatorio” + File.separator + “seriesqueverei.txt”;public void inicia() {
try {
File diretorio = new File(dir);
diretorio.mkdir();InterfaceCompleta stub = (InterfaceCompleta) UnicastRemoteObject.exportObject(this, 0); Registry registry = LocateRegistry.createRegistry(3637); registry.bind("Servidor", stub); System.out.println("Servidor iniciado..."); } catch (RemoteException ex) { System.out.println(ex.getMessage()); } catch (AlreadyBoundException ex) { System.out.println(ex.getMessage()); } catch (Throwable t) { t.printStackTrace(); }
}
public File[] listarArquivos() {
File diretorio = new File(dir);
if (diretorio.listFiles().length > 0) {
File arquivo1 = new File(dir);
File arquivo2 = new File(dir2);
boolean ok = arquivo1.renameTo(arquivo2);
return diretorio.listFiles();
} else {
return null;
}
}public static void main(String[] args) throws RemoteException {
new ServidorCompletoRMI().inicia();
}
}[/code]
Cliente:
[code]
import java.io.BufferedReader;
import java.io.File;
import java.io.FileNotFoundException;
import java.io.FileReader;
import java.io.IOException;
import java.io.InputStreamReader;
import java.rmi.*;
import java.rmi.registry.LocateRegistry;
import java.rmi.registry.Registry;
/*
- To change this template, choose Tools | Templates
- and open the template in the editor.
*/
/**
*
-
@author Munique
*/
public class ClienteCompletoRMI {public ClienteCompletoRMI(){
iniciar();
}public void iniciar() {
String opcao;
BufferedReader br = new BufferedReader(new InputStreamReader(System.in));
try {
Registry registry = LocateRegistry.getRegistry(“localhost”, 3637);
InterfaceCompleta intf = (InterfaceCompleta) registry.lookup(“Servidor”);
opcao = br.readLine();
while (!opcao.equals("")) {
if (opcao.equalsIgnoreCase(“lista”)) {
lista(intf);
}
opcao = br.readLine();
}
} catch (Exception ex) {
ex.printStackTrace();
}
}private void lista(InterfaceCompleta intf) throws RemoteException {
File[] listaArquivo = intf.listarArquivos();
if (listaArquivo == null) {
System.out.println(“Lista de arquivos vazia.”);
} else {
//for (int i = 0; i < listaArquivo.length; i++) {
// System.out.println(listaArquivo[i].getName());
System.out.println(“Passou”);}
}
public static void main(String[] args) throws RemoteException, NotBoundException {
new ClienteCompletoRMI();}
}[/code]
Interface
[code]
import java.io.File;
import java.rmi.Remote;
import java.rmi.RemoteException;
/*
- To change this template, choose Tools | Templates
- and open the template in the editor.
*/
/**
*
-
@author Munique
*/
public interface InterfaceCompleta extends Remote{
//public String enviaDados(String mensagem) throws RemoteException;
public File[] listarArquivos() throws RemoteException;
}[/code]