Reading values from properties file
Hi All,
I am in need of a help from you all.I have a login.jsp which gets username and password as user input and checks in the servlet that if it was admin and admin it will take to index.jsp and if it was other than admin and other users it should take to index1.jsp.For now i am using an if condition to check the values and to dispatch the request.I need to use a properties file for this and need to check by getting the values from the properties file.And also it should check for each entry in properties file and if it finds any matches it should take to the corresponding page.
Please help me in achieving this.
Thanks,
laxmi
Hi All,
I am in need of a help from you all.I have a login.jsp which gets username and password as user input and checks in the servlet that if it was admin and admin it will take to index.jsp and if it was other than admin and other users it should take to index1.jsp.For now i am using an if condition to check the values and to dispatch the request.I need to use a properties file for this and need to check by getting the values from the properties file.And also it should check for each entry in properties file and if it finds any matches it should take to the corresponding page.
Please help me in achieving this.
Thanks,
laxmi
Similar Messages
-
i am facing problem while reading values from properties file ...i am getting null pointer exception earlier i was using jdeveloper10g now i am using 11g
hi TimoHahn,
i am getting following exception in JDeveloper(11g release 2) Studio Edition Version 11.1.2.4.0 but it works perfectly fine in JDeveloper 10.1.2.1.0
Root cause of ServletException.
java.lang.NullPointerException
at java.util.PropertyResourceBundle.handleGetObject(PropertyResourceBundle.java:136)
at java.util.ResourceBundle.getObject(ResourceBundle.java:368)
at java.util.ResourceBundle.getString(ResourceBundle.java:334)
at org.rbi.cefa.master.actionclass.UserAction.execute(UserAction.java:163)
at org.apache.struts.action.RequestProcessor.processActionPerform(RequestProcessor.java:431)
at org.apache.struts.action.RequestProcessor.process(RequestProcessor.java:236)
at org.apache.struts.action.ActionServlet.process(ActionServlet.java:1196)
at org.apache.struts.action.ActionServlet.doPost(ActionServlet.java:432)
at javax.servlet.http.HttpServlet.service(HttpServlet.java:727)
at javax.servlet.http.HttpServlet.service(HttpServlet.java:820)
at weblogic.servlet.internal.StubSecurityHelper$ServletServiceAction.run(StubSecurityHelper.java:227)
at weblogic.servlet.internal.StubSecurityHelper.invokeServlet(StubSecurityHelper.java:125)
at weblogic.servlet.internal.ServletStubImpl.execute(ServletStubImpl.java:300)
at weblogic.servlet.internal.TailFilter.doFilter(TailFilter.java:26)
at weblogic.servlet.internal.FilterChainImpl.doFilter(FilterChainImpl.java:56)
at oracle.security.jps.ee.http.JpsAbsFilter$1.run(JpsAbsFilter.java:119)
at java.security.AccessController.doPrivileged(Native Method)
at oracle.security.jps.util.JpsSubject.doAsPrivileged(JpsSubject.java:315)
at oracle.security.jps.ee.util.JpsPlatformUtil.runJaasMode(JpsPlatformUtil.java:442)
at oracle.security.jps.ee.http.JpsAbsFilter.runJaasMode(JpsAbsFilter.java:103)
at oracle.security.jps.ee.http.JpsAbsFilter.doFilter(JpsAbsFilter.java:171)
at oracle.security.jps.ee.http.JpsFilter.doFilter(JpsFilter.java:71)
at weblogic.servlet.internal.FilterChainImpl.doFilter(FilterChainImpl.java:56)
at oracle.dms.servlet.DMSServletFilter.doFilter(DMSServletFilter.java:139)
at weblogic.servlet.internal.FilterChainImpl.doFilter(FilterChainImpl.java:56)
at weblogic.servlet.internal.WebAppServletContext$ServletInvocationAction.wrapRun(WebAppServletContext.java:3715)
at weblogic.servlet.internal.WebAppServletContext$ServletInvocationAction.run(WebAppServletContext.java:3681)
at weblogic.security.acl.internal.AuthenticatedSubject.doAs(AuthenticatedSubject.java:321)
at weblogic.security.service.SecurityManager.runAs(SecurityManager.java:120)
at weblogic.servlet.internal.WebAppServletContext.securedExecute(WebAppServletContext.java:2277)
at weblogic.servlet.internal.WebAppServletContext.execute(WebAppServletContext.java:2183)
at weblogic.servlet.internal.ServletRequestImpl.run(ServletRequestImpl.java:1454)
at weblogic.work.ExecuteThread.execute(ExecuteThread.java:209)
at weblogic.work.ExecuteThread.run(ExecuteThread.java:178) -
How can i read comments from properties file in the right order??
Hello
I want to build a console that read a properties file and print to the screen the property name, property value and property description and the developer can change the name or the value or the description of the property and update the property file.
But the problem in using the properties class that it doesn�t read the comment and not save the properties in their order so I can�t couple description and name of the property.
Does any one know any utility that do the job or know how to solve the reading the comments problem???
Thank you a lot?sorry but i dont understand how the solution of using
a dot ( property_key.description ) helping me to
solve the problem?
please try to explain it agin.
thank youYou wrote:
"I want to build a console that read a properties file and print to the screen the property name, property value and property description and the developer can change the name or the value or the description of the property and update the property file."
So i'm as developer imagine that somebody edit properties in GUI or console. So you have 3 text fields: property name, property value, and propety description. Then developer save edit changes, then text fields maped to properties file and:
text field "property name" and text field "property value" construct property:
name=valuetext field "property name" adding ".description" and text field "property description" construct property:
name.description=descriptionFor one described property, you will have put two properties.
Thanks! -
How can i remove a key and its value from properties file
hi all,
i want remove a particular key and associated value from the
properties file. is their any standard way of doing?
thanks inadvance
dayahi,
thanks
i am able to remove the key,
one more question how can avoid storing date and time
in properties file.
thanks
daya -
Read value from text file to JTextField
Hi,
I think this is the right place to post this. Although maybe it is not it could be classed as I/O issues?
I have a JFrame with a JTextField which requires the user to enter a value. When they click a JButton "OK". It writes the value to a text file and closes the frame using FileWriter. If they click clear button it writes the value "" to the file. What I want to do is when the frame opens it reads the value from the text file. I have been trying to use FileReader but have not been able to write the code correctly. Any help would be greatly appreciated.
ThanksFile f = yourfile;
BufferedReader br = new BufferedReader(new FileReader(f));
String value = br.readLine();Alex. -
How to read sql from properties file in database control
Hey Guys,
I want to know that how a properties file can be used in bea built-in database control to read SQL.
Any help would be greatly appreciated.
Thanks,
Deepak Kumar
Qwest, Indiahi
ok i tried it like its written in the tutorial...i do it like this:
ClassLoader cl = ResourceAnchor.class.getClassLoader();
props.load( cl.getResourceAsStream(pathname));
-> tha pathname is dvd.properties
and there always appears a NullPointerException: error reading properties file: java.lang.NullPointerException
-angela -
Hi,
I was hoping someone could help me. I am trying to read these values
3.182, 0.02734, 1126.0, 4.998E-4, 0.01581, 11.0, -150.3, 10.46, 3.735, 0.8474, -0.4854, 0.7866, 1.475, 0.9439, 0.769, 0.1846, 0.07678, -0.9491, -1.236, -0.9908, 0.5265, -0.27, 0.3569, -0.09167, 0.1295, -0.04507, 0.1029, -0.03005, 0.0, 0.03752, 0.001151, 0.2935, 74.84, 19080.0, 6.086, etcfrom a txt file. I have done some coding on it but dont seem to be getting the desired results. I want to take these values and put them in a 2D array.. but its not doing it. Can you see any mistakes i have done please ?
public double[][] readFile(){
double[][] dArray = new double[164][37];
int a = 0;
int b = 0;
try
{ FileReader fin = new FileReader("myFile.txt");
BufferedReader in = new BufferedReader(fin);
String line;
while((line = in.readLine()) != null){
String[] value = line.split(", ");
for (int x=0; x<value.length ; x++){
System.out.println("a: "+a+" || b: "+b);
if (b == 37) {
a = a++;
} else
dArray[a] = Double.parseDouble(value[x]);
System.out.println("value: "+dArray[1][1]);
b++;Yes thats because its part of larger code.. it is just a method within my code.
but your right about the catch but so yeah sorry i missed it when i copied pasted. I ve also added you a main method.
public double[][] readFile(){
double[][] dArray = new double[164][37];
int a = 0;
int b = 0;
try
{ FileReader fin = new FileReader("myFile.txt");
BufferedReader in = new BufferedReader(fin);
String line;
while((line = in.readLine()) != null){
String[] value = line.split(", ");
for (int x=0; x<value.length ; x++){
System.out.println("a: "+a+" || b: "+b);
if (b == 37) {
a = a++;
} else
dArray[a] = Double.parseDouble(value[x]);
System.out.println("value: "+dArray[1][1]);
b++;
catch (IOException e){}
return dArray;
public static void main(String[] args) {
new Extract();
}/code] -
How to read values from Property file into BPEL process local variable?
I would like to use a Property file with some parameters e.g.
<myparm1>12345</myparm1>
How can I read from a BPEL process such a Property file and assign it into e.g. local variable "intparm1"?
Where (in which directory) should I put this XML Property file to have it always available for reading?
PeterHi,
You can also use
ora:readFile( ) function as follow :
ora:readFile(xml file location (ex. "file:///D:\\SOA\\FileAdapters\\readFile\\test\\test.xml"),xsd file location (ex."file:///D:\\SOA\\FileAdapters\\readFile\\test\\test.xsd"))
inside the assign activity and assign this to the variable you want.
regards
arababah
Edited by: arababah on Aug 10, 2009 12:55 AM -
Reading value from a text file
hi ,
I have a text filed with values for this field lotid , how in PL/SQL can i make use of the values from this file
in query like select * from tbl1 a where a.lotid = values from text file ?
kindly advise
tks & rdgsFollowing the example Elyo gave:
CREATE TABLE MyTable(line VARCHAR2(4000)) ORGANIZATION EXTERNAL (
default directory MyFolder
access parameters
(fields terminated by ',')
location ('test.txt')
1- use, eg.: fields terminated by ',' to indicate your separator character.
I'm not sure I understand the second question. -
How to read from properties file
Hi,
I am using JSR 168.
while creating a new portlet, a folder gets created with the name as "portlet". Under which is resource package and <PortletName>Bundle.java.
pls tell me how to read from .properties file.
waiting eagerly for some reply
Thanks & Regards,
HP
Edited by: user9003827 on Apr 13, 2010 3:42 AMI think i have mixed it up :)
I have looked at it again and believe you are using regular JSP portlets.
Can you tell what you want to achieve by reading .properties file. Are you meaning the preferences of the portlet or what exactly are you trying to do?
Reading propertie files is easy:
// Read properties file.
Properties properties = new Properties();
try {
properties.load(new FileInputStream("filename.properties"));
String myKey = properties.getProperty("yourKey");
} catch (IOException e) {
}Edited by: Yannick.O on 13-Apr-2010 05:52 -
Reading Design values from readback file
Hi All,
I am trying to understand the process of reading back design signal values from readback file.
I have both the .ll file and the readback.bin file
To get the readback file, I executed the below command:
% readback_hw_device [current_hw_device] -readback_file <filename.rbd> -bin_file <filename.bin>
Now, I want to know the command or process to read the design signal values from this .bin file? Is there any command provided by Xilinx or anything else that I can do to read the signal values?
Rgds
Sapan
Hi Syed,
Thanks for the reply. It was actually my own started thread. I had few questions unanswered from that post:
Question:
The procedure for readback that I am following here is based on the ug908-vivado programming and debugging.
I first uploaded the image on FPGA and then I executed the following commands in Vivado Hardware Manager
% create_hw_bitstream -hw_device [current_hw_device] -mask fpga.msk fpga.bit
% verify_hw_devices [current_hw_device] #### For readback verify
readback_hw_device [current_hw_device] -readback_file <filename.rbd> -bin_file <filename.bin> #####for readback capture
This looks a little different from the one suggested in your document. Can you please confirm if my steps are correct?
Using the above procedure, I did not have to explicitly send readback commands to the FPGA using JTAG as mentioned in doc:
http://www.xilinx.com/support/documentation/sw_manuals/xilinx2015_1/ug908-vivado-programming-debugging.pdf
However the other doc http://www.xilinx.com/support/documentation/application_notes/xapp1230-configuration-readback-capture.pdf mentions sending commands to the device in order to be able to do a readback.
So I am a little confused which one is correct?
Also which document will give the words per frame information for FPGA XC7VX485TFFG1761?
Rgds
Sapan
-
Issue in reading multiple time properties file
Use Case:
I have a page in which i have to show some Outage Messages on page. So I have configured outage message in properties files. This message should me rendered each time when it finds that properties file in class path or it finds the values w.r.t their keys.
So what I decide that I shall write java method and call this method on Loading the page but here what happen is that whenever that page is load each time that reader file will call , that will create memory leak .
So, anyone help me on this. What will be the best approach for that reading multiple times properties file?
I will be grateful for any help you can provide
ThanksHi,
have a bean at applicationScope, somewhat like this
import java.util.HashMap;
public class ApplnProperties {
private HashMap _propMap;
public HashMap getPropMap() {
if(_propMap == null){
//read the properties file and populate _propMap
return _propMap;
}here we put condition _propMap == null so it would be called only once during application lifecycle.
and on page you can refer the prop map like following
#{beanName.propMap['KEY1']}Regards, -
Reading data from flat file Using TEXT_IO
Dear Gurus
I already posted this question but this time i need some other changes .....Sorry for that ..
I am using 10G forms and using TEXT_IO for reading data from flat file ..
My data is like this :-
0|BP-V1|20100928|01|1|2430962.89|27|2430962.89|MUR|20100928120106
9|2430962.89|000111111111|
1|61304.88|000014104113|
1|41961.73|000022096086|
1|38475.65|000023640081|
1|49749.34|000032133154|
1|35572.46|000033093377|
1|246671.01|000042148111|
Here each column is separated by | . I want to read all the columns and want to do some validation .
How can i do ?
Initially my requirement was to read only 2 or 3 columns so i did like this ...
Procedure Pay_Simulator(lfile_type varchar2,lac_no varchar2,lcur varchar2,lno_item number,ltotal number,ldate date,lpay_purp varchar2,lfile_name varchar2)
IS
v_handle utl_file.file_type;
v_filebuffer varchar2(500);
line_0_date VARCHAR2 (10);
line_0_Purp VARCHAR2 (10);
line_0_count Number;
line_0_sum number(12,2);
line_0_ccy Varchar2(3);
line_9_sum Number(12,2);
line_9_Acc_no Varchar2(12);
Line_1_Sum Number(12,2);
Line_1_tot Number(15,2) := 0;
Line_1_flag Number := 0;
lval number;
lacno varchar2(16);
v_file varchar2(20);
v_path varchar2(50);
Begin
v_file := mcb_simulator_pkg.GET_FILENAME(lfile_name); -- For the file name
v_path :=rtrim(regexp_substr( lfile_name , '.*\\' ),'\'); For the Path
v_path := SUBSTR (lfile_name,0, INSTR (lfile_name, '\', -1));
v_handle := UTL_FILE.fopen (v_path, v_file, 'r');
LOOP
UTL_FILE.get_line (v_handle, v_filebuffer);
IF SUBSTR (v_filebuffer, 0, 1) = '0' THEN
SELECT line_0 INTO line_0_date
FROM (SELECT LTRIM (REGEXP_SUBSTR (v_filebuffer, '[^|]+{1}', 1, LEVEL)) line_0, ROWNUM rn
FROM DUAL
CONNECT BY LEVEL <= LENGTH (REGEXP_REPLACE (v_filebuffer, '[^|]*')) + 1)
WHERE rn = 3;
SELECT line_0 INTO line_0_Purp
FROM (SELECT LTRIM (REGEXP_SUBSTR (v_filebuffer, '[^|]+{1}', 1, LEVEL)) line_0, ROWNUM rn
FROM DUAL
CONNECT BY LEVEL <= LENGTH (REGEXP_REPLACE (v_filebuffer, '[^|]*')) + 1)
WHERE rn = 4;
SELECT line_0 INTO line_0_count
FROM (SELECT LTRIM (REGEXP_SUBSTR (v_filebuffer, '[^|]+{1}', 1, LEVEL)) line_0, ROWNUM rn
FROM DUAL
CONNECT BY LEVEL <= LENGTH (REGEXP_REPLACE (v_filebuffer, '[^|]*')) + 1)
WHERE rn = 7;
SELECT line_0 INTO line_0_sum
FROM (SELECT LTRIM (REGEXP_SUBSTR (v_filebuffer, '[^|]+{1}', 1, LEVEL)) line_0, ROWNUM rn
FROM DUAL
CONNECT BY LEVEL <= LENGTH (REGEXP_REPLACE (v_filebuffer, '[^|]*')) + 1)
WHERE rn = 8;
SELECT line_0 INTO line_0_ccy
FROM (SELECT LTRIM (REGEXP_SUBSTR (v_filebuffer, '[^|]+{1}', 1, LEVEL)) line_0, ROWNUM rn
FROM DUAL
CONNECT BY LEVEL <= LENGTH (REGEXP_REPLACE (v_filebuffer, '[^|]*')) + 1)
WHERE rn = 9;
ELSIF SUBSTR (v_filebuffer, 0, 1) = '9' THEN
SELECT line_9 INTO line_9_Acc_no
FROM (SELECT LTRIM (REGEXP_SUBSTR (v_filebuffer, '[^|]+{1}', 1, LEVEL)) line_9, ROWNUM rn
FROM DUAL
CONNECT BY LEVEL <= LENGTH (REGEXP_REPLACE (v_filebuffer, '[^|]*')) + 1)
WHERE rn = 3;
SELECT line_9 INTO line_9_sum
FROM (SELECT LTRIM (REGEXP_SUBSTR (v_filebuffer, '[^|]+{1}', 1, LEVEL)) line_9, ROWNUM rn
FROM DUAL
CONNECT BY LEVEL <= LENGTH (REGEXP_REPLACE (v_filebuffer, '[^|]*')) + 1)
WHERE rn = 2;
ELSIF SUBSTR (v_filebuffer, 0, 1) = '1' THEN
line_1_flag := line_1_flag+1;
SELECT line_1 INTO line_1_sum
FROM (SELECT LTRIM (REGEXP_SUBSTR (v_filebuffer, '[^|]+{1}', 1, LEVEL)) line_1, ROWNUM rn
FROM DUAL
CONNECT BY LEVEL <= LENGTH (REGEXP_REPLACE (v_filebuffer, '[^|]*')) + 1)
WHERE rn = 3;
Line_1_tot := Line_1_tot + line_1_sum;
END IF;
END LOOP;
DBMS_OUTPUT.put_line (Line_1_tot);
DBMS_OUTPUT.PUT_LINE (Line_1_flag);
UTL_FILE.fclose (v_handle);
END;
But now how can i do ? Shall i use like this select Statement for all the columns ?Sorry for that ..
As per our requirement ...
I need to read the flat file and it looks like like this .
*0|BP-V1|20100928|01|1|2430962.89|9|2430962.89|MUR|20100928120106*
*9|2430962.89|000111111111|*
*1|61304.88|000014104113|*
*1|41961.73|000022096086|*
*1|38475.65|000023640081|*
*1|49749.34|000032133154|*
*1|35572.46|000033093377|*
*1|246671.01|000042148111|*
*1|120737.25|000053101979|*
*1|151898.79|000082139768|*
*1|84182.34|000082485593|*
I have to check the file :-
Validation are 1st line should start from 0 else it should raise an error and insert that error into one table .
The for 2nd line also same thing ..it should start from 9 else it should raise an error and insert that error into one table .
Then the 3rd line should start from 1 else it should raise an error and insert that error into one table .
After that i have to do a validation like i will read the 1st line 2nd column .. It should be like this BP-V1 else raise an error and insert that error to a table . Then i will check the 3rd column which is 20100928 , it should be YYYYMMDD format else same thing ERROR.
Then like this for all columns i have different validation .......
Then it will check for the 2nd line 3rd column . this is an account no .1st i will check it should be 12 char else ERROR .Then I will check that what user has imputed in the form.Like for example User putted 111111111 then i will check with this 000111111111 which is there in the 2nd line . I have to add 000 before that Account no which user imputed .
Then the lines which is starting from 1 , i have to take all the 2nd column for all the lines which is starting from 1 and i have to do a sum . After that i have to compare that sum with the value in the 1st lines ( Starting from 0) 6th column . It should be same else ERROR ...
Then same way i have to count all the lines which is starting from 1 . Then i have to compare with the 7th column of 1st line . It should be same . Here in this file it should be 9.
MY CODE IS :-
Procedure Pay_Simulator(lfile_type varchar2,lac_no varchar2,lcur varchar2,lno_item number,ltotal number,ldate date,lpay_purp varchar2,lfile_name varchar2)
IS
v_handle TEXT_IO.file_type;
v_filebuffer varchar2(500);
line_0_date VARCHAR2 (10);
line_0_Purp VARCHAR2 (10);
line_0_count Number;
line_0_sum number(12,2);
line_0_ccy Varchar2(3);
line_9_sum Number(12,2);
line_9_Acc_no Varchar2(12);
Line_1_Sum Number(12,2);
Line_1_tot Number(15,2) := 0;
Line_1_flag Number := 0;
lval number;
lacno varchar2(16);
v_file varchar2(20);
v_path varchar2(50);
LC$String VARCHAR2(50) ;--:= 'one|two|three|four|five|six|seven' ;
LC$Token VARCHAR2(100) ;
i PLS_INTEGER := 2 ;
lfirst_char number;
lvalue Varchar2(100) ;
Begin
v_file := mcb_simulator_pkg.GET_FILENAME(lfile_name); For the file name
v_path :=rtrim(regexp_substr( lfile_name , '.*\\' ),'\'); For the Path
--v_path := SUBSTR (lfile_name,0, INSTR (lfile_name, '\', -1));
Message(lfile_name);
v_handle := TEXT_IO.fopen(lfile_name, 'r');
BEGIN
LOOP
TEXT_IO.get_line (v_handle, v_filebuffer);
lfirst_char := Substr(v_filebuffer,0,1);
--Message('First Char '||lfirst_char);
IF lfirst_char = '0' Then
Loop
LC$Token := mcb_simulator_pkg.Split( v_filebuffer, i , '|') ;
Message('VAL - '||LC$Token);
lvalue := LC$Token;
EXIT WHEN LC$Token IS NULL ;
i := i + 1 ;
End Loop;
Else
Insert into MU_SIMULATOR_output_ERR (load_no,ERR_CODE,ERR_DESC) values (9999,'0002','First line should always start with 0');
Forms_DDL('Commit');
raise form_Trigger_failure;
End if ;
TEXT_IO.get_line (v_handle, v_filebuffer);
lfirst_char := Substr(v_filebuffer,0,1);
LC$Token := mcb_simulator_pkg.Split( v_filebuffer, i , '|') ;
--Message('Row '||LC$Token);
IF lfirst_char = '9' Then
Null;
Else
Insert into MU_SIMULATOR_output_ERR (load_no,ERR_CODE,ERR_DESC) values (8888,'0016','Second line should start with 9');
Forms_DDL('Commit');
raise form_Trigger_failure;
End IF;
LOOP
TEXT_IO.get_line (v_handle, v_filebuffer);
lfirst_char := Substr(v_filebuffer,0,1);
LC$Token := mcb_simulator_pkg.Split( v_filebuffer, i , '|') ;
--Message('Row '||LC$Token);
IF lfirst_char = '1' Then
Null;
Else
Insert into MU_SIMULATOR_output_ERR (load_no,ERR_CODE,ERR_DESC) values (7777,'0022','The third line onward should start with 1');
Forms_DDL('Commit');
raise form_Trigger_failure;
End if;
END LOOP;
--END IF;
END LOOP;
EXCEPTION
When No_Data_Found Then
TEXT_IO.fclose (v_handle);
END;
Exception
When Others Then
Message('Other error');
END;
I am calling the FUNCTION which you gave SPLIT as mcb_simulator_pkg.Split. -
Read data from Excel file and diaplay in Webdynpro
Hi all,
I need some help. I have a Excel file with set of name, phonenumbers . I want to know how to display the data using Webdynpro. Could some one help me. help is appreciated and I promise to award points for right answer.
Thank you
Maruti<b>Hi
i can explain you to read data from Excel file
First You have to download the jxl.jar file. You can get this file from the Below site
</b><a href="http://www.andykhan.com/jexcelapi/download.html">jexcelapi jar</a>
It will be in Compressed Fromat So Unzip it to get the Contents
After Unzipping The File You will get a Folder (jexcelapi/jxl.jar)
Now in NWDS open web dynpro explorer, Right Click Your Project, a popup menu will appear and in that click Properties
You will get window displaying your Project Properties
On Left Side of the window You Will Find "Java Build Path"
Click That "Java Build Path" and you will get 4 Tabs Showing ( Source,Projects,Libraries,Order and Export)
Click Libraries Tab
You will find options many options buttons
In that click the Button "Add External Jars"
You will get Window in order to fecth the jxl.jar file from the location you had stored
After selecting the jxl.jar i will get displayed and click ok
Now Open Navigator
Open Your Project
You will find Lib folder
Copy the jxl.jar to that lib folder
Note : You cannot Read the Content from the excel file directly
First You Have to copy that file to the Server,
And from the Server you can get the file absolute path
With the absolute path you can read the contents of the Excel file
You have to save the Excel file as .xls Format and Not as xlsx format i will not accept that...
You have Upload the Excel file from the Server Using the File Upload UI Element
This Coding will extract 3 columns from the Xls File
Coding
import java.io.File;
import java.io.FileOutputStream;
import java.io.InputStream;
import jxl.Cell;
import jxl.Sheet;
import jxl.Workbook;
import com.sap.fileupload.wdp.IPrivateFileUpload_View;
import com.sap.tc.webdynpro.services.sal.datatransport.api.IWDResource;
public void onActionUpload_File(com.sap.tc.webdynpro.progmodel.api.IWDCustomEvent wdEvent )
//@@begin onActionUpload_File(ServerEvent)
IPrivateFileUpload_View.IContextElement element1 = wdContext.currentContextElement();
IWDResource resource = element1.getFileResource();
element1.setFileName(resource.getResourceName());
element1.setFileExtension(resource.getResourceType().getFileExtension());
//@@end
public void onActionUpload_File_in_Server(com.sap.tc.webdynpro.progmodel.api.IWDCustomEvent wdEvent )
//@@begin onActionUpload_File_in_Server(ServerEvent)
InputStream text=null;
int temp=0;
try
File file = new File(wdContext.currentContextElement().getFileResource().getResourceName().toString());
FileOutputStream op = new FileOutputStream(file);
if(wdContext.currentContextElement().getFileResource()!=null)
text=wdContext.currentContextElement().getFileResource().read(false);
while((temp=text.read())!=-1)
op.write(temp);
op.flush();
op.close();
path = file.getAbsolutePath();
wdComponentAPI.getMessageManager().reportSuccess(path);
catch(Exception e)
e.printStackTrace();
//@@end
public void onActionUpload_Data_into_Table(com.sap.tc.webdynpro.progmodel.api.IWDCustomEvent wdEvent )
//@@begin onActionUpload_Data_into_Table(ServerEvent)
try
Workbook wb =Workbook.getWorkbook(new File(path));
Sheet sh = wb.getSheet(0);
//wdComponentAPI.getMessageManager().reportSuccess("Columns = "+sh.getColumns());
//wdComponentAPI.getMessageManager().reportSuccess("Rows = "+sh.getRows());
int columns = sh.getColumns();
int rows = sh.getRows();
int i=0;
for(int j=1;j<=rows;j++)
ele=wdContext.nodeTable_Data().createTable_DataElement();
Cell c1 = sh.getCell(i,j);
ele.setTab_Name(c1.getContents());
Cell c2 = sh.getCell(i+1,j);
ele.setTab_Degree(c2.getContents());
Cell c3 = sh.getCell(i+2,j);
ele.setTab_Percentage(c3.getContents());
wdContext.nodeTable_Data().addElement(ele);
catch(Exception ex)
wdComponentAPI.getMessageManager().reportSuccess(ex.toString());
//@@end
* The following code section can be used for any Java code that is
* not to be visible to other controllers/views or that contains constructs
* currently not supported directly by Web Dynpro (such as inner classes or
* member variables etc.). </p>
* Note: The content of this section is in no way managed/controlled
* by the Web Dynpro Designtime or the Web Dynpro Runtime.
//@@begin others
String path;
IPrivateFileUpload_View.ITable_DataElement ele;
//@@end
Regards
Chandran S -
Hi Guys,
I am trying to read data from a CSV file character by character. Whats the best way to do this? Any examples around?
Thanks
tzafDoes this mean your file will have multiple lines? And each line would indicate a new record? If so, you should use the BufferedReader and take in each line as a String. Then you can use the StringTokenizer to separate your string into tokens using the comma as your delimiter. From there you can convert the string tokens into whatever form you like, but by default they are already in String form. To make it an Integer I'd use Integer.parseInt().
I will show you some code on how to get the values from your file using the BufferedReader and the StringTokenizer but what you do with those values afterwards I'm going to leave up to you.
File csvfile = new File("myfile.csv");
byte[] fileBuf = new byte[1024]; // buffer for file data
int bytesRead = 0; // number of bytes read
try
BufferedReader fileIn = new BufferedReader( new FileReader( csvfile ));
PrintStream out = new PrintStream( System.out );
String readLine; // stores a line from the file as a string
while( (readLine = fileIn.readLine()) != null )
StringTokenizer tokens = new StringTokenizer( readLine, ",", false);
// false means you don't want to count the commas, only the values
while( tokens.hasMoreTokens() )
String aValue = tokens.nextToken();
// ... do what you want with the value
// ... change to Integer or whatever
out.println(aValue); // Printing the value to the screen
fileIn.close();
}Good luck,
.kim
Maybe you are looking for
-
Required to take backup with out TSM in PROD server.
Dear all, I required to take backup with out using TSM . we have got error in TSM . so that i am getting error . Prod server backup is working automated through TSM . now i need to take Online backup with out using TSM like DEV and QA (Manual backup)
-
How do I get all my music back on my iphone 4?
Cracked the screen on my iphone 4, went to apple shop, they changed it (lovely) and restored all the settings from icloud, all went very well, except I noticed that the music doesn't get restored from itunes Match. In fact it was completely empty. Yo
-
Has anyone had a problem with printing from Elements 9 on a MAC?
When I first installed Elements 9 and tried to print, all I got were blank pages. I contacted adobe support and after an hour on the phone, she referred me to the next level. I then received an email from them asking me to call them and in the mea
-
PB stuck in S-video out mode despite no s-video cable connected!
Greetings, Earlier today I attached a TV to my computer's s-video out to watch some video, afterwards I disconnected the cable and went to use my computer as I would ordinarily. Unfortunately now my Powerbook still shows a TV as being connected despi
-
DATA BASE TABLE AND INTERNAL TABLE
Dear Friends, please help me out in getting complete information about database table and internal table. you can email me at < Removed by moderator - please maintain e-mail iDs in Business Card> Message was edited by: Arun Varadarajan