Solved

how do i define a text file'path in a java program ?

Posted on 2007-11-28
6
2,060 Views
Last Modified: 2013-11-23
Iwill write a java program that shoud read a text file and write its information in a classified table ,
The text file includes :lines,numbers , words ,time and date format ,
I need simple java program with simplest cost of search ,
the text file is a outogenerating report which describe the time ,date ,period of time fo the employee's local or interntional calls.

mport java.io.*;

public class ReadFile{

  public static void main (String []  args){

    File file =new File (args[0]);

    try{

         BufferedReader in=new File(args[0]){

         File file=new File(args[0]);

         try{

             BufferedReader in=new BufferedReader(new(FileReader(file));

             String  s;
 
 

/*sample of the text file:
 

--------   09/24/07   12:10:59   

           RECORD RESTART
 

--------   09/24/07   12:11:16   LINE = 0094   STN = 4002    

           BC = SPEECH

00:00:00   OUTGOING CALL

           DIGITS DIALED    5652443

00:00:33   CALL RELEASED
 

--------   09/24/07   12:10:32   LINE = 0099   STN = 7030    

           BC = SPEECH

00:00:00   OUTGOING CALL

           DIGITS DIALED    56190430

00:01:27   CALL RELEASED
 

--------   09/24/07   12:11:50   LINE = 0094   STN = 4002    

           BC = SPEECH

00:00:00   OUTGOING CALL

           DIGITS DIALED    2408272

00:00:11   CALL RELEASED
 

--------   09/24/07   12:12:02   LINE = 0099   STN = 4002    

           BC = SPEECH

00:00:00   OUTGOING CALL

           DIGITS DIALED    2408272

00:00:05   CALL RELEASED

*/

Open in new window

0
Comment
Question by:deniro1974
6 Comments
 
LVL 11

Accepted Solution

by:
Manish earned 25 total points
ID: 20373159
String fileName =" /foldername/abc.txt";
foldername is under c drive.
0
 
LVL 11

Assisted Solution

by:spoxox
spoxox earned 25 total points
ID: 20393555
An alternative, in the unlikely event that isn't good enough:

String fileName="d:\\foldername\\abc.txt";

Note the backslash must be escaped as shown.
0
 
LVL 2

Expert Comment

by:pshersby
ID: 20468832
You should really use something like
             String separator = System.getProperty("file.separator");

To get the correct character to put in between the bits of the file path and to ensure your code is platform indepndent.

But did you want to know how to define the file path (you app passes the filename in on the command line) or how to parse the file?
0
 
LVL 1

Expert Comment

by:cypher_punk
ID: 20572402
Hi,

For windows machine, u need to escape the escape sequence '\' while writing the path.

format:
Drive name:\\\\dir name\\dir name\\file name.extension

e.g. e:\\\\rock\\pritam\\math.txt

For more info refer to this link.
http://java.sun.com/j2se/1.5.0/docs/api/
and check for the class "File".
0

Featured Post

Is Your Active Directory as Secure as You Think?

More than 75% of all records are compromised because of the loss or theft of a privileged credential. Experts have been exploring Active Directory infrastructure to identify key threats and establish best practices for keeping data safe. Attend this month’s webinar to learn more.

Question has a verified solution.

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

Suggested Solutions

Title # Comments Views Activity
groupSum5 challenge 5 68
PHP and Soap 3 45
split string containing \r\n in Java 46 38
XSLT XML 4 13
Introduction In my previous article (http://www.experts-exchange.com/Microsoft/Development/MS-SQL-Server/SSIS/A_9150-Loading-XML-Using-SSIS.html) I showed you how the XML Source component can be used to load XML files into a SQL Server database, us…
Introduction This article is the second of three articles that explain why and how the Experts Exchange QA Team does test automation for our web site. This article covers the basic installation and configuration of the test automation tools used by…
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 how to properly install Eclipse with the necessary JDK, and will take a look at an introductory Java program. Download Eclipse installation zip file: Extract files from zip file: Download and install JDK 8: Open Eclipse and …

914 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