Solved

Read Data From a File

Posted on 2004-04-22
11
353 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
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
  • 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
Independent Software Vendors: We Want Your Opinion

We value your feedback.

Take our survey and automatically be enter to win anyone of the following:
Yeti Cooler, Amazon eGift Card, and Movie eGift Card!

 

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

Free Tool: IP Lookup

Get more info about an IP address or domain name, such as organization, abuse contacts and geolocation.

One of a set of tools we are providing to everyone as a way of saying thank you for being a part of the community.

Question has a verified solution.

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

Suggested Solutions

Title # Comments Views Activity
arguments to jar 5 39
ejb wildfly example 2 72
jsp login check 12 53
Java: anonymous class 4 38
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…
In this post we will learn different types of Android Layout and some basics of an Android App.
Viewers learn about the “for” loop and how it works in Java. By comparing it to the while loop learned before, viewers can make the transition easily. You will learn about the formatting of the for loop as we write a program that prints even numbers…
Video by: Michael
Viewers learn about how to reduce the potential repetitiveness of coding in main by developing methods to perform specific tasks for their program. Additionally, objects are introduced for the purpose of learning how to call methods in Java. Define …

749 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