I have the following server
public class handlerfereastra extends JFrame implements ActionListener {
Socket sc;
JFileChooser jf1,jf2;
public handlerfereastra(Socket sc)
{
this.sc=sc;
setSize(500,500);
setVisible(true);
setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
Container x=getContentPane();
x.setLayout(new FlowLayout());
JButton butrec=new JButton("Select path to receive");
JButton butsen=new JButton("Select file to send");
butrec.addActionListener(this);
butsen.addActionListener(this);
x.add(butrec);
x.add(butsen);
setVisible(true);
new receptioneaza(sc).start();
}
@Override
public void actionPerformed(ActionEvent e) {
if(e.getActionCommand().compareTo("Select path to receive")==0)
{
jf1=new JFileChooser();
jf1.showOpenDialog(this);
}
else if(e.getActionCommand().compareTo("Select file to send")==0)
{
jf2=new JFileChooser();
jf2.showOpenDialog(this);
try {
BufferedInputStream bus=new BufferedInputStream(new FileInputStream(jf2.getSelectedFile()));
PrintStream ps=new PrintStream(sc.getOutputStream());
int count;
byte[]bs=new byte[2048];
System.out.println(jf2.getSelectedFile());
while((count=bus.read(bs))>0)
{
ps.write(bs,0,count);
ps.flush();
}
ps.flush();
bus.close();
} catch (FileNotFoundException e1) {
// TODO Auto-generated catch block
e1.printStackTrace();
} catch (IOException e1) {
// TODO Auto-generated catch block
e1.printStackTrace();
}
}
}
}
and here is my client class
public class receptioneaza extends Thread {
Socket sc;
public receptioneaza(Socket sc)
{
this.sc=sc;
}
@Override public void run()
{
while(true)
{
try {
InputStream in=sc.getInputStream();
byte[]buf=new byte[2048];
File fl=new File("salveaza");
FileOutputStream fos=new FileOutputStream(fl);
byte[] buffer = new byte[1024];
int count;
while((count=in.read(buffer)) >0){
fos.write(buffer,0,count);
fos.flush();
}
fos.close();
} catch (IOException e) {
// TODO Auto-generated catch block
e.printStackTrace();
}
}
}
}
I want to send files from server to client and the other way.The problem is that when i send a file from server is goes well but if i send a second one from the server i don't see that the file modified.It remains as the first file i send.The same goes for client.What makes them to remain unmodified after i send it for the first time?