Results 1 to 2 of 2
  1. #1
    ans2104 is offline Member
    Join Date
    Feb 2010
    Posts
    1
    Rep Power
    0

    Default java rmi buffer error

    trying to implement rmi which takes the file name automatically from the server.
    it transfers in command line heres a code ive made changes to take the first file
    bt im gettin the foll errors

    FileImpl.java:30: '.class' expected
    return buffer[];
    ^
    1 error

    here is my code
    import java.io.*;
    import java.rmi.*;
    import java.rmi.server.UnicastRemoteObject;

    public class FileImpl extends UnicastRemoteObject
    implements FileInterface {

    private String name;

    public FileImpl(String s) throws RemoteException{
    super();
    name = s;

    }

    public byte[] downloadFile(){
    try {

    File dir=new File("C:\\Program Files\\Java\\jdk1.5.0_07\\bin\\a");
    File x[]=dir.listFiles();
    for (int i =0;i<x.length;i++){
    File file = x[i];
    byte buffer[] = new byte[(int)file.length()];
    BufferedInputStream input = new
    BufferedInputStream(new FileInputStream(x[i].getName()));
    input.read(buffer,0,buffer.length);
    input.close();

    }
    return buffer[];
    }
    catch(Exception e){
    System.out.println("FileImpl: "+e.getMessage());
    e.printStackTrace();
    return(null);
    }
    }
    }

    i have tried return(buffer); bt it gives similar errors hope u can help
    thank u

  2. #2
    FON
    FON is offline Senior Member
    Join Date
    Dec 2009
    Location
    Belgrade, Serbia
    Posts
    368
    Rep Power
    5

    Default

    This line is problem:

    return buffer[];

    Without going into your logic and purpose of this
    here is method without errors that returns byte array - buffer:

    Java Code:
    public byte[] downloadFile(){
    		
    		[B]byte buffer[] = null;[/B]
    		try {
    
    			File dir=new File("C:\\Program Files\\Java\\jdk1.5.0_07\\bin\\a");
    			
    			File x[]=dir.listFiles();
    			
    			for (int i = 0; i<x.length; i++){
    				File file = x[i];
    				
    				[B]buffer[/B] = new byte[(int)file.length()];
    				BufferedInputStream input = new BufferedInputStream(new FileInputStream(x[i].getName()));
    				input.read(buffer,0,buffer.length);
    				input.close();
    
    			}
    			[B]return buffer;[/B]
    		} 
    		catch(Exception e){
    			System.out.println("FileImpl: "+e.getMessage());
    			e.printStackTrace();
    			return(null);
    		}
    	}
    cheers!

Similar Threads

  1. Buffer Example help.
    By bert682 in forum Threads and Synchronization
    Replies: 0
    Last Post: 11-27-2009, 09:26 AM
  2. how to read the same req buffer twice
    By leejava in forum New To Java
    Replies: 2
    Last Post: 11-17-2009, 07:29 PM
  3. Buffer
    By QPRocky in forum Networking
    Replies: 2
    Last Post: 02-02-2009, 03:54 PM
  4. Replies: 2
    Last Post: 08-27-2008, 03:24 PM
  5. Help with String Buffer
    By mathias in forum AWT / Swing
    Replies: 1
    Last Post: 08-07-2007, 06:52 AM

Tags for this Thread

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •