Results 1 to 3 of 3

Thread: Stack (file location)

  1. #1

    Thread Starter
    Lively Member
    Join Date
    Nov 1999
    Location
    Belgium
    Posts
    98

    Stack (file location)

    Hi,

    I have this peace of Java code and I would like to know how to change the file location in the code. (only a filename (test.txt) is in the code and I would like to add a path (c:\test.txt).

    Code:
    import java.io.*;
    import java.util.*;
    
    class StackDemoUsingArrays{	
    		static String [] myString = new String[3];	
    		static int count = 0;	
    		
    		public static void main (String args[]) 	throws Exception {		
    			BufferedReader br = new BufferedReader
    			(new InputStreamReader(new FileInputStream(new File("test.txt")))); // <-- I want to change this	
    			String str = "";		
    		while((str = br.readLine()) != null){			
    			push(str.trim());		}		
    			System.out.println(pop());	}	
    			
    		public static String pop(){		
    				
    			if(count<=0) {			
    			System.out.println("Cannot pop an empty stack");			
    			System.exit(0);		}		
    			return myString[-- count]; 	}	
    				
    		public static void push(Object o){		
    			if(count == myString.length){			
    			String [] myString1 = new String[myString.length*2];			
    			System.arraycopy((Object)myString,0,(Object)myString1,0,myString.length);			
    			myString = myString1;		}		
    			myString[count] = o.toString();		
    			count++;	}
    			}

  2. #2
    Addicted Member Mrs Kensington's Avatar
    Join Date
    Sep 2001
    Location
    Dorset, UK
    Posts
    144
    would you not just change it to c:\test.txt???

    One word of warning. that code would only work on Windows Machines as there is no such thing as c: on unix (can't speak for mac, but its based on unix so i assume its the same)

    Mrs K
    Ford? Theres an infinite number of monkeys outside that want to talk to you about a script of hamlet they've produced!

  3. #3
    Dazed Member
    Join Date
    Oct 1999
    Location
    Ridgefield Park, NJ
    Posts
    3,418
    Yeah wouldn't you just add in the path? I wouldn't hardcode the file name though. File names are seriously platform dependent.

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  



Click Here to Expand Forum to Full Width