I'm trying to copy a file to an android device using Wifi. For what i cant tell the creation of the file works, but i can't find it anywhere...
I've try to use the DDMS on Eclipse, but there's nothing on the Data folder... for what i read on other topics, the file should be located on the data folder of the App.. but there's no folder anywhere...
This is the code
package com.ejemplo.cliente;
import java.io.BufferedReader;
import java.io.BufferedWriter;
import java.io.File;
import java.io.FileOutputStream;
import java.io.IOException;
import java.io.InputStream;
import java.io.InputStreamReader;
import java.io.OutputStreamWriter;
import java.net.Socket;
import java.net.UnknownHostException;
import android.app.Activity;
import android.os.Bundle;
import android.widget.TextView;
import android.widget.Toast;
public class ClienteSocket extends Activity {
Socket socket;
String IP = "192.168.1.101";
Integer Puerto = 4444;
TextView Mensaje;
public void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.main);
Mensaje = (TextView)findViewById(R.id.Mensaje);
try {
socket = new Socket(IP,Puerto);
Mensaje.setText("Conectado");
InputStream input = socket.getInputStream();
BufferedReader inReader = new BufferedReader(new InputStreamReader(socket.getInputStream()));
BufferedWriter outReader = new BufferedWriter(new OutputStreamWriter(socket.getOutputStream()));
String filename = inReader.readLine();
if ( !filename.equals("") ){
outReader.write("READY\n");
outReader.flush();
Mensaje.setText("Request Acepted");
FileOutputStream wr = openFileOutput(filename,MODE_WORLD_READABLE);
OutputStreamWriter osw = new OutputStreamWriter(wr);
byte[] buffer = new byte[socket.getReceiveBufferSize()];
int bytesReceived = 0;
while((bytesReceived = input.read(buffer))>0)
{
osw.write(bytesReceived);
Toast.makeText(this, "Transfering", Toast.LENGTH_SHORT).show();
}
osw.flush();
osw.close();
Mensaje.setText("File Received");
}
} catch (UnknownHostException e) {
Mensaje.setText("error 1" + e.getMessage());
} catch (IOException e) {
Mensaje.setText("error 2" + e.getMessage());
}
}
}