Solved

Read Data From a File

Posted on 2004-04-22
11
347 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
 

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
Find Ransomware Secrets With All-Source Analysis

Ransomware has become a major concern for organizations; its prevalence has grown due to past successes achieved by threat actors. While each ransomware variant is different, we’ve seen some common tactics and trends used among the authors of the malware.

 
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:mayankeagle
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:mayankeagle
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

Maximize Your Threat Intelligence Reporting

Reporting is one of the most important and least talked about aspects of a world-class threat intelligence program. Here’s how to do it right.

Join & Write a Comment

Suggested Solutions

For customizing the look of your lightweight component and making it look lucid like it was made of glass. Or: how to make your component more Apple-ish ;) This tip assumes your component to be of rectangular shape and completely opaque. (COD…
Introduction This article is the last of three articles that explain why and how the Experts Exchange QA Team does test automation for our web site. This article covers our test design approach and then goes through a simple test case example, how …
Viewers learn about the third conditional statement “else if” and use it in an example program. Then additional information about conditional statements is provided, covering the topic thoroughly. Viewers learn about the third conditional statement …
This tutorial covers a step-by-step guide to install VisualVM launcher in eclipse.

760 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

Need Help in Real-Time?

Connect with top rated Experts

20 Experts available now in Live!

Get 1:1 Help Now