I am fixing my server many times and now I'm stuck again.
So if I'm trying to send a file to my file through my client, then the person can see the im sending the file. I do not really know how to explain it though. Im just trying to send a file so that other customers can accept it and save it. But as soon as I press the button picture (it should automatically send a picture on a desktop that I have placed) This works,
Connections are accepted; Local Host / 127.0.0.1 - 1500 Send C: / User / Berry / Desktop / CO / Cao 6. JPG (15306 bytes) The server has closed the connection
But I do not have anything In the desktop and my serverguide, I can see that it says:
Exception reading exception: java.io.StreamCorruptedException: Invalid type code: FF
I do not know how to fix it and I need some ideas that how do I get it I can do that.
Sendpic.java
Public Zero SendPic () throws IOException {JFileChooser chooser = new JFileChooser (); String FILESEND = "C: / Users / Berry / Desktop / CO / Cao 6. JPG"; FileInputStream fis = null; Buffardinputstream bis = null; OutputStream OS = Faucet; Try {// file file myFile = new file (FILESEND); Byte [mybytearray = new byte [(int) myFile.length ()]; Fis = New FileInputStream (myFile); BIS = new buffer inputstream (FIS); Bis.read (mybytearray, 0, mybytearray.length); OS = socket.getOutputStream (); System.out.println ("Sending" + FILESEND + "(" + mybytearray.length + "bytes)"); Os.write (mybytearray, 0, mybytearray.length); } Hold (IOException e) {e.printStackTrace (); }}
getPic.Java
last stable file FILE_SIZE = 6022386; Public zero getPic () throws IOException {JFileChooser chooser = new JFileChooser (); String FILETORECEIVED = "C: / user / barry / desktop /"; Int bytes read; Int current = 0; FileOutputStream fos = Faucet; BufferOperputStream Boss = Faucet; Try {byte [mybytearray = new byte [FILE_SIZE]; InputStream = socket.getInputStream (); Fos = new FileOutputStream (FILETORECEIVED); Bose = new BufferedOutputStream (fos); Bitesrad = is Reid (Mybietairie, 0, Mybytere length.); Current = bytes read; Do {BitsRed = is Reed (Mybittairie, On, (Mybietayre, Long-Present)); If (bytes read> = 0) current + = bytes read; } While (bytes read> gt; -1); boss. Write (Mybittirer, 0, present); Bos.flush (); System.out.println ("File" + FILE_SIZE + "downloaded (" + current + "reading bytes)"); } Finally {if (fos! = Null) fos.close (); If (boss! = Null) boss Close (); }}
Action Affected `
Public Zero Action Perf.Ef (Action Event e) {Object Button = eTates ource (); If (button == BTN image) {try {controller. } Grip (IOException e1) {// TODO Auto-generated Cache Block e1.printStackTrace (); } Return; } `
No comments:
Post a Comment