this question has answer here:
i've client , server. server maintains file , client request it. so, is
file configuration_file=new file(configuration.doc); system.out.println (configuration_file.exist()); //return true in=new bufferedreader(new inputstreamreader(socket.getinputstream())); oos=new objectoutputstream(socket.getoutputstream()); string line; while ((line=in.readline())!=null) { if (line.equals("configuration file")) oos.writeobject(configuration_file); oos.flush(); } } when receive on client file, throws ioexception. program works if pass absolute path when create file (client , server on same machine moment, think passed through socket reference path , both client , server can see that). question is: possible sending file object through socket channel directly or must convert array of bytes , send array? thank in advance
you need convert bytes , send bytes. example server may have file in f:/out.txt if send actual file object client, client might not have f: drive @ all. furthermore file class makes use of lot native methods. serializing , de-serializing never idea.
Comments
Post a Comment