---서버쪽---
public class ServerTest {
/**
* @param args
*/
public static void main(String[] args) {
// TODO Auto-generated method stub
ServerSocket ss=null;
Socket soc= null;
BufferedOutputStream bos=null;
FileInputStream fis=null;
File filename;
File filePath;
try{
ss=new ServerSocket(12122);
System.out.println("서버 시작한다");
}catch(Exception e){
System.out.println("서버 시작 안되었어요~~~!!");
System.exit(-1);
}
while(true){
try{
String str;
System.out.println("1111");
soc=ss.accept();
System.out.println("22222");
str=soc.toString();
System.out.println("접속자 정보:"+str);
filename=new File("D:\\1");
String strlist[]=filename.list();
for(int x=0;x<strlist.length;x++){
//System.out.println(strlist[x]);
filePath=new File("D:\\1\\"+strlist[x]);
int size=(int) filePath.length();
bos=new BufferedOutputStream(soc.getOutputStream(),size);
fis=new FileInputStream(filePath);
byte i[] = new byte[512];
System.out.println("filePath.size : "+filePath.length());
while( fis.read(i) != -1){
bos.write(i);
bos.flush();
}
}
bos.close();
fis.close();
}catch(Exception e1){
e1.printStackTrace();
}
}
}
}
---클라이언트 쪽---
public class ThreeG_Dialog extends Activity {
/** Called when the activity is first created. */
//private InetAddress ia=null;
private Socket soc;
private Button threeG_yes;
private Button threeG_no;
private File filename;
private File f2;
private File filePath;
private FileOutputStream fos=null;
private BufferedInputStream bis=null;
//String strlist[]={"0.mp3","1.mp3","2.mp3","3.mp3","4.mp3","5.mp3","6.mp3","7.mp3","8.mp3","9.mp3","10.mp3"};
@Override
public void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.threegdialog);
// TODO Auto-generated method stub
threeG_yes=(Button)findViewById(R.id.threeg_yes);
threeG_no=(Button)findViewById(R.id.threeg_no);
threeG_yes.setOnClickListener(new OnClickListener(){
@Override
public void onClick(View v) {
// TODO Auto-generated method stub
try {
soc=new Socket("220.67.140.59",12122);
System.out.println("111");
//soc=new Socket("220.67.140.60",12122);
System.out.println("222");
} catch (IOException e1) {
// TODO Auto-generated catch block
e1.printStackTrace();
}
try {
bis=new BufferedInputStream(soc.getInputStream());
//DataInputStream dis=new DataInputStream(bis);
//FileInputStream fis=new FileInputStream(f2);
filePath=new File("/sdcard/Jwent/voca/");
fos=new FileOutputStream(filePath);
System.out.println("list=====>"+filePath);
System.out.println("sucess");
byte i[] = new byte[512];
try {
while((bis.read(i)) != -1){
fos.write(i);
}
bis.close();
//dis.close();
fos.close();
} catch (IOException e) {
// TODO Auto-generated catch block
e.printStackTrace();
}
} catch (FileNotFoundException e) {
// TODO Auto-generated catch block
e.printStackTrace();
} catch (IOException e) {
// TODO Auto-generated catch block
e.printStackTrace();
}
finish();
}
});
threeG_no.setOnClickListener(new OnClickListener(){
@Override
public void onClick(View v) {
// TODO Auto-generated method stub
finish();
}
});
}
}
지금 파일 전송은 되는데 서버에서 보내면 그냥 1개의 파일에 다 들어가버려요 ㅜㅜ 서버에서 해당 폴더안의 파일을 전송해서 클라이언트쪽인 폰의 sdcard 경로에 똑같이 들어와주어야하는데 안되네용 ㅠㅠ 너무 힘들어요 좀 도와주세요