Link to home
Start Free TrialLog in
Avatar of deniro1974
deniro1974

asked on

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

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

ASKER CERTIFIED SOLUTION
Avatar of Manish
Manish
Flag of India image

Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial
SOLUTION
Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial
Avatar of pshersby
pshersby

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?
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".