cancel
Showing results for 
Search instead for 
Did you mean: 

Writing into a .properties file

Former Member
0 Kudos

Hi all,

I need to write some data into a .properties file which exists under src/mime/component/<component-name>. And for that reason I wrote following lines of code into wdDoInit() method of the view:

String url = WDURLGenerator.getResourcePath(wdComponentAPI.getDeployableObjectPart(), "myFile.properties");

File file = new File(url);

Properties properties = new Properties();

properties.setProperty("Key1", "Value1");

try

{

FileOutputStream fileOutputStream = new FileOutputStream(url);

properties.store(fileOutputStream, null);

fileOutputStream.close();

}

catch (Exception e)

wdComponentAPI.getMessageManager().reportException("Fiporp file write " + e,true);

But after deployment also no data has been written into the properties file. I am not sure whether i am missing something or doing some mistake. Please help me to come out of this situation.

Thanks in advance,

Ganpati Jha

Accepted Solutions (0)

Answers (2)

Answers (2)

Former Member
0 Kudos

you can do something like this

IWDResourceHandler resourceHandlerForQuestions =

WDResourceHandler.createResourceHandlerForCurrentSession();

IWDResourceHandler resourceHandlerForAnswers =

WDResourceHandler.createResourceHandlerForCurrentSession();

// Load the resource bundle "Questions.properties" located

// in the package "com.sap.tc.webdynpro.tutorials.quiz.resources.Questions"

// for locale set in the resource handler.

resourceHandlerForQuestions.loadResourceBundle(

"com.sap.tc.webdynpro.tutorials.quiz.resources.Questions",

this.getClass().getClassLoader());

resourceHandlerForAnswers.loadResourceBundle(

"com.sap.tc.webdynpro.tutorials.quiz.resources.Answers",

this.getClass().getClassLoader());

// get the number of question-answer-pairs contained in the resource bundle

int size = Integer

.valueOf(resourceHandlerForQuestions.getString("SIZE")).intValue();

//===== STEP 2: Create context node elements of the type QuizData =========

// begin populating context node QuizData

Collection questions = new ArrayList();

for (int i = 0; i < size; i++) {

// instantiate the new context node element of type QuizData

IPublicQuiz.IQuizDataElement quizDataElement =

wdContext.createQuizDataElement();

// set contained context value attributes

quizDataElement.setQuestion(resourceHandlerForQuestions.getString("Q"+i));

quizDataElement.setAnswer(resourceHandlerForAnswers.getString("A"+i));

quizDataElement.setCounter(String.valueOf(i1)"/"+String.valueOf(size));

// add new context node element of the type QuizeData to ArrayList

questions.add(quizDataElement);

}

//===== STEP 3: Bind collection of Q&A pairs to context value node QuizData ====

// Bind collection of context node elements to context value node QuizData

wdContext.nodeQuizData().bind(questions);

//@@end

former_member751941
Active Contributor
0 Kudos

Hi Ganpati,

Steps to create “myFile.properties”

-


Step 1: Go to the Navigator perspective.

Select Your Component (under src/mimes/components/< webdynpro component>

)

Right click =>New =>

Step2: A wizard will appear select "Simple" from left and "File" from the right

Then Click Next button.

Step3: Give the "File Name" myFile.properties and Finish. myFile.properties File will be created.

Step4 : select the "source" tab and add the correct keys & values.

Check this threads.

Regards,

Mithu