• Status: Solved
  • Priority: Medium
  • Security: Public
  • Views: 205
  • Last Modified:

i want to write file name and file path in message properties file

i want to write file name and file path in message properties file

Could you please give me a java code for that
0
Manikandan Thiagarajan
Asked:
Manikandan Thiagarajan
  • 5
  • 4
  • 2
  • +1
1 Solution
 
objectsCommented:
FileOutputStream out = new FileOutputStream("my.properties");
Properties props = new Properties();
prop.put(file.getName, file.getAbsolutePath());
props.store(out);
out.close();
0
 
CEHJCommented:
Please expand on your needs
0
 
Manikandan ThiagarajanSenior consultantAuthor Commented:
Filename1=c:\\foo\\f1.xt

filename2 = c:\\foo\\f2.txt

iwant to store in properties file like that
0
Cloud Class® Course: CompTIA Cloud+

The CompTIA Cloud+ Basic training course will teach you about cloud concepts and models, data storage, networking, and network infrastructure.

 
objectsCommented:
FileOutputStream out = new FileOutputStream("my.properties");
Properties props = new Properties();
prop.put("filename1", file1.getAbsolutePath());
prop.put("filename2", file2.getAbsolutePath());
props.store(out);
out.close();
0
 
cmalakarCommented:
For the above solution, you need file objects which you can create like this.

File file1 = new File("c:\\foo\\f1.xt");
File file2 = new File("c:\\foo\\f2.txt");
FileOutputStream out = null;
try{
  out = new FileOuptutStream("my.properties");
  Properties props = new Properties();
  prop.put("Filename1", file1.getAbsolutePath());
  prop.put("Filename2", file2.getAbsolutePath());
  props.store(out);
}catch(Exception e){
  e.printStackTrace();
}finally{
if(out != null)
  out.close();
}

Open in new window


If you don't have file objects, You can store like this...

FileOutputStream out = null;
try{
  out = new FileOuptutStream("my.properties");
  Properties props = new Properties();
  prop.put("Filename1", "c:\\foo\\f1.txt");
  prop.put("Filename2", "c:\\foo\\f2.txt");
  props.store(out);
}catch(Exception e){
  e.printStackTrace();
}finally{
if(out != null)
  out.close();
}

Open in new window

0
 
Manikandan ThiagarajanSenior consultantAuthor Commented:
 props.store(out,"InwardRemittance")

properties sotre accept two parameters, so how could i mention in properties.store
0
 
cmalakarCommented:
props.store(out, "This will be a comment, Give some string");
0
 
Manikandan ThiagarajanSenior consultantAuthor Commented:
i want to append the properties file

How could i do that

in my program it would shows only 7 th file name and path

but i want to print
1.....7
i want to append the properties file
how could i do that


while(rs.next()) {
                System.out.println("Insidw While");
                System.out.println("inside now test");
                tempInputDTO = new CustomInwardRemittanceDTO();
              //  System.out.println("MaxRows"+crs.getMaxRows());
                  //  int count = rs.getInt("count");
                    //System.out.println(count);
                   
                     file = new File("C:\\inwardremittance\\inwardremittance"+i+".txt");
                        if(!file.exists()){
                              file.createNewFile();
                              System.out.println("New file \"myfile.txt\" has been created"); 
                               Clob clob = rs.getClob(1);
                                 if(clob == null) {
                                    System.out.println("clob is null");
                                     }
                                     
                                     else
                                     {

                             
                                     // Reader reader =rs.getCharacterStream("rawMessage");
                    //System.out.println(crs.getString("rawMessage"));
                     Reader reader=clob.getCharacterStream();
                                       FileWriter fw = new FileWriter(file);
                                 
                                   int j=-1;

                                   while ( (j=reader.read())!=-1)
                                   {
                                   fw.write(j);
                                   }
                             fw.close();
                             if(file.length()>0) {
                             
                                 FileOutputStream out = new FileOutputStream("D:\\Properties\\InwardRemittance.properties");
                                 Properties props = new Properties();
                                 props.put("inwardremittance",file.getAbsolutePath());                                 
                                 props.store(out,"InwardRemittance");
                                 out.close();

                             }
                                     }
                             i++;   
                    }

Open in new window

0
 
cmalakarCommented:

FileOutputStream out = new FileOutputStream("D:\\Properties\\InwardRemittance.properties");
   Properties props = new Properties();
//Bought above lines, before while loop

while(rs.next()) {
                System.out.println("Insidw While");
                System.out.println("inside now test");
                tempInputDTO = new CustomInwardRemittanceDTO();
              //  System.out.println("MaxRows"+crs.getMaxRows());
                  //  int count = rs.getInt("count");
                    //System.out.println(count);
                   
                     file = new File("C:\\inwardremittance\\inwardremittance"+i+".txt");
                        if(!file.exists()){
                              file.createNewFile();
                              System.out.println("New file \"myfile.txt\" has been created"); 
                               Clob clob = rs.getClob(1);
                                 if(clob == null) {
                                    System.out.println("clob is null");
                                     }
                                     
                                     else
                                     {

                             
                                     // Reader reader =rs.getCharacterStream("rawMessage");
                    //System.out.println(crs.getString("rawMessage"));
                     Reader reader=clob.getCharacterStream();
                                       FileWriter fw = new FileWriter(file);
                                 
                                   int j=-1;

                                   while ( (j=reader.read())!=-1)
                                   {
                                   fw.write(j);
                                   }
                             fw.close();
                             if(file.length()>0) {
                             
                              
                                 props.put("inwardremittance",file.getAbsolutePath());                                 
                                 

                             }
                                     }
                             i++;   
                    }
					
					
		//Put these statements after your while loop ends..
		props.store(out,"InwardRemittance");
                out.close();

Open in new window

0
 
cmalakarCommented:
What I did is, Open the properties file before while loop,

put the properties inside your "if(file.length()>0) {" condition.

and closing the file , after the while loop
0
 
Manikandan ThiagarajanSenior consultantAuthor Commented:
why time is printed for all lin properties file

how could i restrict that
0
 
cmalakarCommented:
that is a comment,  written only once in a property file at the top.

I believe, we cannot avoid that. It is used to identify, when the properties file is modified.
0
 
CEHJCommented:
You need to write the properties to a file in the normal way if you want to avoid the date appearing
0
Question has a verified solution.

Are you are experiencing a similar issue? Get a personalized answer when you ask a related question.

Have a better answer? Share it in a comment.

Join & Write a Comment

Featured Post

Free Tool: Port Scanner

Check which ports are open to the outside world. Helps make sure that your firewall rules are working as intended.

One of a set of tools we are providing to everyone as a way of saying thank you for being a part of the community.

  • 5
  • 4
  • 2
  • +1
Tackle projects and never again get stuck behind a technical roadblock.
Join Now