Want to protect your cyber security and still get fast solutions? Ask a secure question today.Go Premium

x
  • Status: Solved
  • Priority: Medium
  • Security: Public
  • Views: 203
  • 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
Concerto's Cloud Advisory Services

Want to avoid the missteps to gaining all the benefits of the cloud? Learn more about the different assessment options from our Cloud Advisory team.

 
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

Featured Post

Concerto Cloud for Software Providers & ISVs

Can Concerto Cloud Services help you focus on evolving your application offerings, while delivering the best cloud experience to your customers? From DevOps to revenue models and customer support, the answer is yes!

Learn how Concerto can help you.

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