class Send implements Runnable {
Socket socket = null;
OutputStream os = null;
File file = null;
FileInputStream fis = null;
byte[] bytes;
boolean flag = true;
DataOutputStream dos=null;
Send(File file) {
this.file = file;
}
public void connect() {
try {
socket = new Socket("192.168.1.100", 9991);
os = socket.getOutputStream();
dos = new DataOutputStream(os);
fis= new FileInputStream(file);
String a = file.getAbsolutePath();
} catch (IOException e) {
}
bytes = new byte[1024];
int length=0;
try {
while(true&flag){
while ((length = fis.read(bytes, 0, bytes.length))> 0) {
dos.write(bytes, 0, length);
dos.flush();
}
try {
new Thread().sleep(1);
} catch (InterruptedException e) {
e.printStackTrace();
}
}
} catch (IOException e) {
e.printStackTrace();
}
finally{
if(fis!=null){
try {
fis.close();
} catch (IOException e) {
e.printStackTrace();
}
}
if(dos!=null){
try {
dos.flush();
dos.close();
} catch (IOException e) {
e.printStackTrace();
}
}
}
}
public void run() {
connect();
}
}
上面的是android端的程序这个就是实时传输视频的程序,但是传输到PC端的视频无法播放,请问哪一位大神能给我解决一下,很急
下面的是PC端服务器接受视频的数据
import java.io.BufferedOutputStream;
import java.io.DataInputStream;
import java.io.File;
import java.io.FileOutputStream;
import java.io.IOException;
import java.io.InputStreamReader;
import java.net.ServerSocket;
import java.net.Socket;
public class bbbb{
public static void main(String[] args){
try {
ServerSocket ss=new ServerSocket(9991);
Socket socket=ss.accept();
System.out.print("hh");
new Thread(new oo(socket)).start();
} catch (IOException e) {
e.printStackTrace();
}
}
}
class oo implements Runnable{
int length;
Socket socket;
DataInputStream dis;
FileOutputStream fos;
oo(Socket socket){
this.socket=socket;
}
public void run() {
try {
dis=new DataInputStream(socket.getInputStream());
fos=new FileOutputStream(new File("C:/Users/lenovo/Desktop/gg1/a.mp4"));
byte[] bytes=new byte[1024];
while((length=dis.read(bytes,0,bytes.length))>0){
fos.write(bytes, 0, length);
fos.flush();
try {
new Thread().sleep(1);
} catch (InterruptedException e) {
// TODO Auto-generated catch block
e.printStackTrace();
}
}
} catch (IOException e) {
e.printStackTrace();
}
finally{
if(fos!=null){
try {
fos.flush();
fos.close();
System.out.print("接收完毕!");
} catch (IOException e) {
e.printStackTrace();
}
}
}
}
}