LinuxQuestions.org
Share your knowledge at the LQ Wiki.
Home Forums Tutorials Articles Register
Go Back   LinuxQuestions.org > Forums > Non-*NIX Forums > Programming
User Name
Password
Programming This forum is for all programming questions.
The question does not have to be directly related to Linux and any language is fair game.

Notices


Reply
  Search this Thread
Old 02-22-2005, 09:45 AM   #1
dummyagain
Member
 
Registered: Sep 2003
Posts: 74

Rep: Reputation: 15
java io write file


I use a client to send file to server, however, i can send the file with equal size, equal filename and filesize. But when i opened the sent file in the server, the file is a blank one. I would like to ask how to solve that

client side
try{
s = new Socket(ServerIP, ServerPort);
File f = new File(sentFile.getName());
fis = new FileInputStream(f);
os = s.getOutputStream();
while (fis.available()>0){
os.write(fis.read());
}
fis.close();
os.close();
s.close();
}catch(IOException ioe){
System.out.println("Get a Error in socket");
}



server side
try{
ss = new ServerSocket(port);
}catch(IOException e){
System.out.println(e);
}

while (true){
try{
s = ss.accept();
fos = new FileOutputStream(new File(filename));
is = s.getInputStream();

for (int i=0; i<fileSize; i++)
fos.write(is.read());



thank you for your help
 
Old 02-22-2005, 10:05 AM   #2
csfalcon
Member
 
Registered: Jun 2004
Location: MD
Distribution: Fedora Core
Posts: 269

Rep: Reputation: 31
You need to close the FileOutputStream on the server side.
 
Old 02-22-2005, 10:11 AM   #3
dummyagain
Member
 
Registered: Sep 2003
Posts: 74

Original Poster
Rep: Reputation: 15
i had closed it but i haven't shown the code
 
Old 02-23-2005, 04:50 PM   #4
Looking_Lost
Senior Member
 
Registered: Apr 2003
Location: Eire
Distribution: Slackware 12.0, OpenSuse 10.3
Posts: 1,120

Rep: Reputation: 45
If you haven't already sorted it out try on the client side like

Code:
	int data;

	while( (data=fis.read()) != -1){
		os.write(data);
		}

	fis.close();
	os.close();

and on the server side the reverse

	int data;

	while( (data=is.read()) != -1){
		fos.write(data);
	      }

	fos.close();
	is.close();

Last edited by Looking_Lost; 02-23-2005 at 04:53 PM.
 
  


Reply



Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is Off
HTML code is Off



Similar Threads
Thread Thread Starter Forum Replies Last Post
grip : no write access to write encoded file bidouilleur Linux - Software 5 10-09-2010 09:23 PM
Can not write to file in Java irfanhab Programming 7 12-05-2005 12:01 AM
Write to file omerlh Programming 6 10-17-2005 04:02 AM
forrtl: severe (47): write to READONLY file, unit 5, file /dev/pts/1 terrence Programming 1 10-01-2005 10:22 PM
Grip- "no write access to write encoded file" Alvis Linux - Software 4 01-06-2004 04:18 PM

LinuxQuestions.org > Forums > Non-*NIX Forums > Programming

All times are GMT -5. The time now is 11:08 PM.

Main Menu
Advertisement
My LQ
Write for LQ
LinuxQuestions.org is looking for people interested in writing Editorials, Articles, Reviews, and more. If you'd like to contribute content, let us know.
Main Menu
Syndicate
RSS1  Latest Threads
RSS1  LQ News
Twitter: @linuxquestions
Open Source Consulting | Domain Registration