Solved

Read Data From a File

Posted on 2004-04-22
11
354 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
Industry Leaders: 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

Instantly Create Instructional Tutorials

Contextual Guidance at the moment of need helps your employees adopt to new software or processes instantly. Boost knowledge retention and employee engagement step-by-step with one easy solution.

Question has a verified solution.

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

Suggested Solutions

Title # Comments Views Activity
Unhandled exception type Exception 18 63
ejb on wildfly 5 61
convert Absolute path to relative path of FTP location 7 47
junit initializtion error 2 17
For beginner Java programmers or at least those new to the Eclipse IDE, the following tutorial will show some (four) ways in which you can import your Java projects to your Eclipse workbench. Introduction While learning Java can be done with…
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…
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…

738 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