Want to win a PS4? Go Premium and enter to win our High-Tech Treats giveaway. Enter to Win

x
?
Solved

Read Data From a File

Posted on 2004-04-22
11
Medium Priority
?
357 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 2000 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
Technology Partners: 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 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

Hire Technology Freelancers with Gigs

Work with freelancers specializing in everything from database administration to programming, who have proven themselves as experts in their field. Hire the best, collaborate easily, pay securely, and get projects done right.

Question has a verified solution.

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

Java contains several comparison operators (e.g., <, <=, >, >=, ==, !=) that allow you to compare primitive values. However, these operators cannot be used to compare the contents of objects. Interface Comparable is used to allow objects of a cl…
This was posted to the Netbeans forum a Feb, 2010 and I also sent it to Verisign. Who didn't help much in my struggles to get my application signed. ------------------------- Start The idea here is to target your cell phones with the correct…
Viewers learn about the scanner class in this video and are introduced to receiving user input for their programs. Additionally, objects, conditional statements, and loops are used to help reinforce the concepts. Introduce Scanner class: Importing…
This tutorial will introduce the viewer to VisualVM for the Java platform application. This video explains an example program and covers the Overview, Monitor, and Heap Dump tabs.
Suggested Courses

610 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