Solved

Read Data From a File

Posted on 2004-04-22
11
351 Views
Last Modified: 2010-03-31
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
Comment
Question by:tricks801
  • 3
  • 3
  • 2
  • +2
11 Comments
 
LVL 92

Expert Comment

by:objects
ID: 10894795
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
 
LVL 92

Accepted Solution

by:
objects earned 500 total points
ID: 10894803
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
 

Author Comment

by:tricks801
ID: 10894946
is filename expecting the whole path as a string?
0
Live: Real-Time Solutions, Start Here

Receive instant 1:1 support from technology experts, using our real-time conversation and whiteboard interface. Your first 5 minutes are always free.

 

Author Comment

by:tricks801
ID: 10894952
or is filename really File n = new File("C:\\Emails\\" + fileName);
0
 
LVL 92

Expert Comment

by:objects
ID: 10895030
you should use the full path, otherwise it will look for the file relative to where you code is run from.
0
 
LVL 5

Expert Comment

by:b_vishwajit
ID: 10895109
And you have to catch exceptions too. Dont forget try {} catch {} blocks.
0
 
LVL 23

Expert Comment

by:rama_krishna580
ID: 10895220
0
 
LVL 30

Expert Comment

by:Mayank S
ID: 10896334
0
 
LVL 5

Expert Comment

by:b_vishwajit
ID: 10897023
Pretty funny. Sab desi ek heen jagein pein kabja kar liya o bhi points paane ke liye. Just foolin around.
0
 
LVL 30

Expert Comment

by:Mayank S
ID: 10911024
b_vishwajit, Please don't post comments in languages which everybody doesn't understand.
0
 
LVL 5

Expert Comment

by:b_vishwajit
ID: 10911147
If that offended anyone here then I am sorry.Take it ez.
0

Featured Post

Live: Real-Time Solutions, Start Here

Receive instant 1:1 support from technology experts, using our real-time conversation and whiteboard interface. Your first 5 minutes are always free.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Suggested Solutions

Title # Comments Views Activity
Application launch issue with Apache Tomcat 5 42
eclipse argument 14 60
tomcat startup error 5 59
sql import cannot be resolved jsp 3 19
By the end of 1980s, object oriented programming using languages like C++, Simula69 and ObjectPascal gained momentum. It looked like programmers finally found the perfect language. C++ successfully combined the object oriented principles of Simula w…
Java Flight Recorder and Java Mission Control together create a complete tool chain to continuously collect low level and detailed runtime information enabling after-the-fact incident analysis. Java Flight Recorder is a profiling and event collectio…
Viewers will learn about arithmetic and Boolean expressions in Java and the logical operators used to create Boolean expressions. We will cover the symbols used for arithmetic expressions and define each logical operator and how to use them in Boole…
This tutorial covers a practical example of lazy loading technique and early loading technique in a Singleton Design Pattern.

776 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question