Results 1 to 6 of 6
  1. #1
    Redefine12 is offline Member
    Join Date
    Feb 2012
    Posts
    66
    Rep Power
    0

    Default Eliminate Pathing Implementation of .csv Data Source

    Hi All,

    I've got a Java functionality/capability question. I've got an application that currently uses a

    Java Code:
    Scanner s = new Scanner(new File("C:\\PCQ\\A_R.csv"));
    implementation to gather data from a .csv file. At a recent code review meeting, my supervisor stated that any 'pathing' specified in application code is illegal for security reasons in our enterprise. Which leads me to my question: Is there a way to implement and distribute a compiled .jar that contains a data source such as above-mentioned without including path coding within the application code? A fellow programmer here threw out the words "Relative/Absolute Pathing", but I'm not seeing many solutions in my research thus far.

    Any input is appreciated. Cheers.

  2. #2
    Sierra is offline AN21XX
    Join Date
    Mar 2012
    Location
    Munich
    Posts
    297
    Rep Power
    3

    Default Re: Eliminate Pathing Implementation of .csv Data Source

    Yes you can use a configuration file for that purpose... then it is not in your code. ^^
    You maybe better also include the csv file in the jar file by including it in the final export of your file.

    The last part of your statement makes me think that you maybe just want to have no "absolute" pathing information in your code - then you may specify the path relative to your program folder e.g.:
    "../Configuration/blabla.csv"

  3. #3
    Tolls is online now Moderator
    Join Date
    Apr 2009
    Posts
    12,184
    Rep Power
    20

    Default Re: Eliminate Pathing Implementation of .csv Data Source

    1. Where is this file going to be when distributed?
    2. Is it read only?
    Please do not ask for code as refusal often offends.

    ** This space for rent **

  4. #4
    Redefine12 is offline Member
    Join Date
    Feb 2012
    Posts
    66
    Rep Power
    0

    Default Re: Eliminate Pathing Implementation of .csv Data Source

    I've been trying and trying and I can't seem to get to a solution. I'll illustrate with an example. I want to distribute a .jar file that contains the application code. The source file "foo.csv" will be located in the same root folder, e.g.:

    C:\PATH\application.jar
    C:\PATH\foo.csv

    I need to specify the pathing for foo.csv within the application .jar file so that whatever the root folder is, the .jar will be able to 'see' foo.csv.

    Below is an example of a hard-coded pathing as I understand it. How can I modify per above specifictions?

    Java Code:
    import java.awt.Container;
    import java.io.File;
    import java.io.IOException;
    import java.util.Scanner;
    import javax.swing.JFrame;
    import javax.swing.JLabel;
    import javax.swing.JPanel;
    
    public class path {
    
    	public static void main(String[] args) throws IOException {
    				
    		JPanel panel = new JPanel();
    		
    		File f = new File("C:\\PATH\\test.txt");
    		Scanner s = new Scanner(f);
    		while(s.hasNextLine()){
    			String l = s.nextLine();
    			JLabel label = new JLabel(l);
    			panel.add(label);	
    		}
    		
    		JFrame frame = new JFrame("Path Test"); 
    		frame.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE); 
    		Container contentPane = frame.getContentPane(); 		
    		contentPane.add(panel);
            frame.setSize(600,400);
            frame.setLocationRelativeTo(null);
    		frame.setVisible(true);
    
    	}
    
    }

  5. #5
    Redefine12 is offline Member
    Join Date
    Feb 2012
    Posts
    66
    Rep Power
    0

    Default Re: Eliminate Pathing Implementation of .csv Data Source

    Hmm, perhaps:

    Java Code:
    import java.awt.Container;
    import java.io.File;
    import java.io.IOException;
    import java.util.Scanner;
    import javax.swing.JFrame;
    import javax.swing.JLabel;
    import javax.swing.JPanel;
    
    public class path {
    
    	public static void main(String[] args) throws IOException {
    				
    		JPanel panel = new JPanel();		
    		//File f = new File("C:\\PATH\\test.txt");
    		File f = new File(".\\test.txt");
    		Scanner s = new Scanner(f.getCanonicalFile());
    		while(s.hasNextLine()){
    			String l = s.nextLine();
    			JLabel label = new JLabel(l);
    			panel.add(label);	
    		}
    		
    		JFrame frame = new JFrame("Path Test"); 
    		frame.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE); 
    		Container contentPane = frame.getContentPane(); 		
    		contentPane.add(panel);
            frame.setSize(600,400);
            frame.setLocationRelativeTo(null);
    		frame.setVisible(true);
    	}
    }
    with C:\Program Files\eclipse\workspace\path\test.txt

  6. #6
    Tolls is online now Moderator
    Join Date
    Apr 2009
    Posts
    12,184
    Rep Power
    20

    Default Re: Eliminate Pathing Implementation of .csv Data Source

    Ensure the classpath in the manifest includes . and that should work.
    Please do not ask for code as refusal often offends.

    ** This space for rent **

Similar Threads

  1. Replies: 2
    Last Post: 01-06-2012, 05:23 PM
  2. to log the very fast data source
    By jerry_nf in forum Threads and Synchronization
    Replies: 3
    Last Post: 03-26-2011, 06:21 AM
  3. Replies: 1
    Last Post: 01-31-2011, 03:38 AM
  4. Matlab data type implementation & speed
    By uzil24 in forum Advanced Java
    Replies: 3
    Last Post: 10-24-2009, 03:00 AM
  5. Problem for iReport (Data Source )
    By tlgkumar in forum Advanced Java
    Replies: 1
    Last Post: 11-27-2007, 08:39 AM

Posting Permissions

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