JAVA .properties file

后端 未结 3 2101
日久生厌
日久生厌 2021-01-25 14:27

having a lil issue, i have create a properties file :

config.properties located in ../resource/config.properties

this is the file currently :

des         


        
3条回答
  •  故里飘歌
    2021-01-25 14:48

    I wonder whats the issue...I tested your code and it works fine...are you getting compilation error or runtime error?

    import java.io.FileInputStream;
    import java.io.IOException;
    import java.util.Properties;
    
    
    public class Test1 {
    
        /**
         * @param args
         */
        public static void main(String[] args) {
            new Test1().loadProp();
        }
    
        Properties prop = new Properties();
    
        public void loadProp() {
            try {
                prop.load(new FileInputStream("c:/Test/Computer.txt"));
                System.out.println(prop.getProperty("destinationPDF"));
                System.out.println(prop.getProperty("destination"));
                System.out.println(prop.getProperty("fileList"));
    
            } catch (IOException ex) {
                ex.printStackTrace();
            }
        }
    
    }
    

    Output:

    D:/Documents/NetBeansProjects/printing~subversion/fileupload/web/resources/pdf/ D:/Documents/NetBeansProjects/printing~subversion/fileupload/Uploaded/ D:/Documents/NetBeansProjects/printing~subversion/fileupload/web/resources/Directory Files/directoryFiles.txt

提交回复
热议问题