• Status: Solved
  • Priority: Medium
  • Security: Public
  • Views: 362
  • Last Modified:

Read Data From a File

how can i read data from a text file line by line and send them from client to server and then write them to a text file line by line so that i appears as if i had sent the actual data, but in reality just read the file and sent its contents.

Thanks
0
tricks801
Asked:
tricks801
  • 3
  • 3
  • 2
  • +2
1 Solution
 
objectsCommented:
BufferedReader in = new BufferedReader(new FileReader(filename));
PrintWriter out = new PrintWriter(new OutputStreamWriter(socket.getOutputStream()));
String line = null;
while (null!=(line=in.readLine()))
{
   out.println(line);
}
in.close();
out.close();

0
 
objectsCommented:
Similiarily to recieve the file:

BufferedReader in = new BufferedReader(new InputStreamReader(socket.getInputStream()));
PrintWriter out = new PrintWriter(new FileWriter(filename));
String line = null;
while (null!=(line=in.readLine()))
{
   out.println(line);
}
in.close();
out.close();
0
 
tricks801Author Commented:
is filename expecting the whole path as a string?
0
Cloud Class® Course: Microsoft Office 2010

This course will introduce you to the interfaces and features of Microsoft Office 2010 Word, Excel, PowerPoint, Outlook, and Access. You will learn about the features that are shared between all products in the Office suite, as well as the new features that are product specific.

 
tricks801Author Commented:
or is filename really File n = new File("C:\\Emails\\" + fileName);
0
 
objectsCommented:
you should use the full path, otherwise it will look for the file relative to where you code is run from.
0
 
b_vishwajitCommented:
And you have to catch exceptions too. Dont forget try {} catch {} blocks.
0
 
Mayank SAssociate Director - Product EngineeringCommented:
0
 
b_vishwajitCommented:
Pretty funny. Sab desi ek heen jagein pein kabja kar liya o bhi points paane ke liye. Just foolin around.
0
 
Mayank SAssociate Director - Product EngineeringCommented:
b_vishwajit, Please don't post comments in languages which everybody doesn't understand.
0
 
b_vishwajitCommented:
If that offended anyone here then I am sorry.Take it ez.
0
Question has a verified solution.

Are you are experiencing a similar issue? Get a personalized answer when you ask a related question.

Have a better answer? Share it in a comment.

Join & Write a Comment

Featured Post

Cloud Class® Course: C++ 11 Fundamentals

This course will introduce you to C++ 11 and teach you about syntax fundamentals.

  • 3
  • 3
  • 2
  • +2
Tackle projects and never again get stuck behind a technical roadblock.
Join Now