Read file from directory
Hi all,
CALL 'C_DIR_READ_START' ID 'DIR' FIELD P_DIR
ID 'FILE' FIELD IT_FILEDIR-FILENAME
IF SY-SUBRC <> 0.
WRITE:/ 'Incorrect File'.
EXIT.
ENDIF.
This is my code for read particular file in server.
Iam passing p_dir and filename correctly .but this statement still failing .Can any one help me in this issue?
Please see the following sample program for viewing the application server file system and reading the files into your ABAP program.
report zrich_0001 .
data: begin of itab occurs 0,
rec(1000) type c,
end of itab.
data: wa(1000) type c.
data: p_file type localfile.
data: ifile type table of salfldir with header line.
parameters: p_path type salfile-longname
default '/usr/sap/TST/DVEBMGS01/data/'.
call function 'RZL_READ_DIR_LOCAL'
exporting
name = p_path
tables
file_tbl = ifile
exceptions
argument_error = 1
not_found = 2
others = 3.
loop at ifile.
format hotspot on.
write:/ ifile-name.
hide ifile-name.
format hotspot off.
endloop.
at line-selection.
concatenate p_path ifile-name into p_file.
clear itab. refresh itab.
open dataset p_file for input in text mode.
if sy-subrc = 0.
do.
read dataset p_file into wa.
if sy-subrc <> 0.
exit.
endif.
itab-rec = wa.
append itab.
enddo.
endif.
close dataset p_file.
loop at itab.
write:/ itab.
endloop.
REgards,
Rich Heilman
Similar Messages
-
Read file from directory, update contents of the each file
hai,
I could not understand how to debug the error i have now.
target
1- read the files from directory // i able ot do this part
2- for each file
for each file read the content & compare with the existing List & update the list // i able to do this part
when i try to combine both parts , i got some following error
run:
E:\java\check\100130.ixf
Error: children[i] (The system cannot find the file specified)
BUILD SUCCESSFUL (total time: 2 seconds)
i can see from the code that children[i] only gives the error when i use that in the second part of the code.
can any one help me on this??
Thanks
Priyan
the original code
import java.io.BufferedReader;
import java.io.DataInputStream;
import java.io.File;
import java.io.FileInputStream;
import java.io.InputStreamReader;
import java.io.RandomAccessFile;
import java.util.ArrayList;
public class CompareList
public static void main(String[] args){
ArrayList a1 = new ArrayList();
ArrayList a2 = new ArrayList();
a1.add("1");
a1.add("2");
a1.add("3");
a1.add("4");
a1.add("5");
a1.add("6");
a1.add("7");
a1.add("8");
a1.add("9");
a1.add("10");
a1.add("11");
a1.add("12");
a1.add("13");
a1.add("14");
a1.add("15");
a1.add("16");
a1.add("17");
a1.add("18");
a1.add("19");
a1.add("20");
a1.add("21");
a1.add("22");
a1.add("23");
a1.add("24");
a1.add("25");
a1.add("26");
a1.add("27");
a1.add("28");
a1.add("29");
a1.add("30");
a1.add("31");
a1.add("32");
a1.add("33");
a1.add("34");
a1.add("35");
a1.add("36");
a1.add("37");
a1.add("38");
a1.add("39");
a1.add("40");
a1.add("41");
a1.add("42");
a1.add("43");
a1.add("44");
a1.add("45");
a1.add("46");
a1.add("47");
a1.add("48");
a1.add("49");
a1.add("50");
a1.add("51");
a1.add("52");
try{
File dir = new File("E:\\java\\check");
File[] children = dir.listFiles();
if (children == null) {
System.out.println("does not exist or is not a directory");
else {
for (int i = 0; i < children.length; i++) {
System.out.println( children);
FileInputStream fstream = new FileInputStream("children[i]");
DataInputStream in = new DataInputStream(fstream);
BufferedReader br = new BufferedReader(new InputStreamReader(in));
String strLine;
while ((strLine = br.readLine()) != null) {
String line =strLine.substring(0,2);
// Print the content on the console
//System.out.println(line);
a2.add(line);
} // end of add list2
if (a1.size() > a2.size())
int k = 0;
for (int l = 0; l < a2.size(); l++)
if (!((String)a1.get(l)).equals((String)a2.get(l)))
//System.out.println((String)a2.get(i));
// System.out.println("dd");
k = l;
k++;
for (int l = k; l < a1.size(); l++)
System.out.println((String)a1.get(l));
String str = "children[l]";
File file = new File(str);
RandomAccessFile rand = new RandomAccessFile(file,"rw");
rand.seek(file.length()); //Seek to end of file
rand.writeBytes((String)a1.get(i)); //Write end of file
rand.writeBytes("., 0.");
rand.writeBytes("\n");
}// end of comparing and updating the list2
in.close();
catch (Exception e){//Catch exception if any
System.err.println("Error: " + e.getMessage());thanks for the information.
i tried, the error
like this
run:
E:\java\check\100130.ixf
java.lang.StringIndexOutOfBoundsException: String index out of range: 2
at java.lang.String.substring(String.java:1935)
at CompareList.main(CompareList.java:84)
BUILD SUCCESSFUL (total time: 0 seconds)this comes because in my code i used children[i] as string in the later part
else {
for (int i = 0; i < children.length; i++) {
System.out.println( children);
FileInputStream fstream = new FileInputStream(children[i]);
DataInputStream in = new DataInputStream(fstream);
BufferedReader br = new BufferedReader(new InputStreamReader(in));
String strLine;
while ((strLine = br.readLine()) != null) {
String line =strLine.substring(0,2);
a2.add(line);
System.out.println(line);
} // end of add list2
if (a1.size() > a2.size())
int k = 0;
for (int l = 0; l < a2.size(); l++)
if (!((String)a1.get(l)).equals((String)a2.get(l)))
//System.out.println((String)a2.get(i));
// System.out.println("dd");
k = l;
k++;
for (int l = k; l < a1.size(); l++)
System.out.println((String)a1.get(l));
String str = "children[l]";
File file = new File(str);
RandomAccessFile rand = new RandomAccessFile(file,"rw");
rand.seek(file.length()); //Seek to end of file
rand.writeBytes((String)a1.get(i)); //Write end of file
rand.writeBytes("., 0.");
rand.writeBytes("\n");
rand.close();
}// end of comparing and updating the list2
in.close();
i stil could not figure out it yet. do u have any clue with this. -
How to delete a READ ONLY file from Directory
Hi Friends,
how to delete a READ ONLY file from Directory , file is in my system only.
Please help me .
note: its read only file.
Thank you.
Karthik.hI,
try with this statement.
delete dataset <datasetname>.
this will definitely work.
Regards,
Nagaraj -
PI sender communication channel not reading files from NFS directory
Hello,
I have a sender communication channel configured to read file from NFS directory which is on ECC server. A program in ECC generates the file and puts it on the ECC server in the output directory. PI sender communication channel is supposed to pickup this file and process it. If I give the NFS path as the source directory, I am getting error: Configured source directory '//Server/DIR/OUT' does not exist. I tried putting '
Server\DIR\OUT' too but same error. Do I have to add the NFS path of ECC into PI as logical path?
Any suggestions?
Thanks,
SangitaHello Sangita,
Your ECC server is an external system, therefore you need to activate FTP service in that system and use the transport protocol FTP:
http://help.sap.com/saphelp_nw04/helpdata/en/e3/94007075cae04f930cc4c034e411e1/content.htm
You can use NFS protocol when you have a local directory in XI server.
Best Regards,
.Luis Bernal. -
Reading files and directory from a directory
ublic static void readFromDirectory(String dirName) {
// stop word ArrayLists
ArabicStop();
EnglishStop();
FrenchStop();
SpanishStop();
DutchStop();
File dir = new File(dirName);
if (dir.isDirectory()) {
String[] child = dir.list();
System.out.println("hi Iam here");
for (int i = 0; i < child.length; i++) {
readFromDirectory(child.toString());
File[] files = dir.listFiles();
if (files == null) {
System.out.println("There are no files in this Directory ");
} else {
for (int j = 0; j < files.length; j++) {
String filename = files[j].toString();
readFile(filename);
if (dirName.equalsIgnoreCase("English")
|| dirName.equalsIgnoreCase("Nonenglish")) {
for (int i = 0; i < a2.size(); i++) {
keyWord = a2.get(i).toString();
//System.out.println("===" + keyWord + "===" + "KeyWord");
for (int a = 0; a < text.size(); a++) {
String t1 = text.get(a).toString();
if (keyWord.equalsIgnoreCase(t1)) {
count++;
//System.out.println("Found at:" + files[j] + " file");
keyWCount = count;
m1.put(keyWord, keyWCount);
//System.out.println(m1.get(keyWord));
count = 0;
} else if (dirName.equalsIgnoreCase("Spanish")) {
for (int i = 0; i < a5.size(); i++) {
keyWord = a5.get(i).toString();
//System.out.println("===" + keyWord + "===" + "KeyWord");
for (int a = 0; a < text.size(); a++) {
String t1 = text.get(a).toString();
if (keyWord.equalsIgnoreCase(t1)) {
count++;
//System.out.println("Found at:" + files[j] + " file");
keyWCount = count;
m1.put(keyWord, keyWCount);
//System.out.println(m1.get(keyWord));
count = 0;
//System.out.println(m1);
} else if (dirName.equalsIgnoreCase("French")) {
for (int i = 0; i < a3.size(); i++) {
keyWord = a3.get(i).toString();
//System.out.println("===" + keyWord + "===" + "KeyWord");
for (int a = 0; a < text.size(); a++) {
String t1 = text.get(a).toString();
if (keyWord.equalsIgnoreCase(t1)) {
count++;
//System.out.println("Found at:" + files[j] + " file");
keyWCount = count;
m1.put(keyWord, keyWCount);
//System.out.println(m1.get(keyWord));
count = 0;
public static void main(String[] args) {
int countText = 0;
int c;
test t1 = new test();
System.out.println("IN NON - ENGLISH DOCUMENTS - P :");
t1.readFromDirectory("NonEnglish");
for (int j = 0; j < text.size(); j++) {
if (!text.get(j).toString().equalsIgnoreCase("")) {
countText++;
c = countText;
//System.out.println(c);
//System.out.println(text.size());
for (int i = 0; i < a2.size(); i++) {
String word = a2.get(i).toString();
String m = (m1.get(word)).toString();
double x = Double.parseDouble(m);
System.out.println(word + ":" + (x / c) * 100 + " %");
I wanna read text files from directory that contain - lots of other directorys... and by using this code I have error,,,
Can anyone help me plzzz
Edited by: Shamma on Oct 9, 2008 3:32 AMYou actually have more than 1 problem: you cannot traverse directories recursively and you get a NullPointerException.
For the first problem you might want to verify what this statement returns:
child.toString() (I honestly don't understand why you are calling toString() on a String object, but that's not the real problem!)
You probably expect it to be a full absolute path.
The NullPointerException has already been pointed out by masijade. -
HOW TO READ MULTIPLE FILES FROM DIRECTORY
i have a directory with 100 .sql insert scripts.i want to read all .sql files from directory and execute the insert script automatically.
Let's suppose you have 3 files: "first.sql", "second.sql" and "third.sql". Create a file named "all.sql" in the same directory, containing this:
@@first.sql
@@second.sql
@@third.sqlRun "all.sql". -
Reading file from oracle directory at client side
Hi,
I have a SWING app. which connects to an Oracle db.
My goal is to read files from oracle directory with java through JDBC. I export some dumps with datapump and they need to be transferred to a client machine. There is no access to oracle directory at network filesystem level.
Please advice!
TIA, SandorAn Oracle Directory has an underlying OS directory associated with it, Oracle just overlays it's control structure onto an existing folder in the OS. You can manipulate the files with stored procedures in Oracle or at the OS level from outside of Oracle.
If you manipulate the files from the OS level, outside of Oracle, you may need a refresh of the Oracle Directory structure. -
Reading file from an external folder.
Iam tring to read an external file from the C:\ drive. Given below is the code.
DATA LV_XLS(100) TYPE C.
DATA LV_CONTENT TYPE XSTRING.
LV_XLS = 'C:\XML\Report.xls'
READ DATASET LV_XLS INTO LV_CONTENT.
But when i execute iam getting an error - FILE NOT FOUND. How do i read file from an external folder. My requirement is to strictly read from an external folder. Please help.
If this is not possible please advice as to how the file could be moved to the SAP root directory. Iam not able to locate the root.hi,
This is the code to read a excel file from the local system.
Read data set you are using in your code corresponds to files on application server thats the reason its throwing an error.
* Parameter variable declaration for browsing the file location *
PARAMETERS:
p_file TYPE ibipparms-path OBLIGATORY.
data:
it_text TYPE truxs_t_text_data .
AT SELECTION-SCREEN ON VALUE-REQUEST FOR p_file.
CALL FUNCTION 'F4_FILENAME'
EXPORTING
program_name = syst-cprog
* DYNPRO_NUMBER = SYST-DYNNR
field_name = ' '
IMPORTING
file_name = p_file.
START-OF-SELECTION.
CALL FUNCTION 'TEXT_CONVERT_XLS_TO_SAP'
EXPORTING
* I_FIELD_SEPERATOR =
* I_LINE_HEADER =
i_tab_raw_data = it_text
i_filename = p_file
TABLES
i_tab_converted_data = t_cust
EXCEPTIONS
conversion_failed = 1
OTHERS = 2
IF sy-subrc <> 0.
* MESSAGE ID SY-MSGID TYPE SY-MSGTY NUMBER SY-MSGNO
* WITH SY-MSGV1 SY-MSGV2 SY-MSGV3 SY-MSGV4.
ENDIF.
This is to read a text file from local system.
CALL FUNCTION 'GUI_UPLOAD'
EXPORTING
filename = 'D:\FILEINTERFACE\file.TXT'
* FILETYPE = 'ASC'
has_field_separator = 'X'
* HEADER_LENGTH = 0
* READ_BY_LINE = 'X'
* DAT_MODE = ' '
* CODEPAGE = ' '
* IGNORE_CERR = ABAP_TRUE
* REPLACEMENT = '#'
* IMPORTING
* FILELENGTH =
* HEADER =
TABLES
data_tab = t_kna1
* EXCEPTIONS
* FILE_OPEN_ERROR = 1
* FILE_READ_ERROR = 2
* NO_BATCH = 3
* GUI_REFUSE_FILETRANSFER = 4
* INVALID_TYPE = 5
* NO_AUTHORITY = 6
* UNKNOWN_ERROR = 7
* BAD_DATA_FORMAT = 8
* HEADER_NOT_ALLOWED = 9
* SEPARATOR_NOT_ALLOWED = 10
* HEADER_TOO_LONG = 11
* UNKNOWN_DP_ERROR = 12
* ACCESS_DENIED = 13
* DP_OUT_OF_MEMORY = 14
* DISK_FULL = 15
* DP_TIMEOUT = 16
* OTHERS = 17
IF sy-subrc <> 0.
* MESSAGE ID SY-MSGID TYPE SY-MSGTY NUMBER SY-MSGNO
* WITH SY-MSGV1 SY-MSGV2 SY-MSGV3 SY-MSGV4.
ENDIF.
PS. In both of the above mentioned function modules make sure that the file structure is similar to the internal tables used.
Thanks
Sharath -
Hi,
Trying to read files from a dir on my site using a JSP and bean. I've tried nearly every option for the filepath I can think of and it doesn't seem to be finding the file...
Here's the bit:
String URL = "images\\wedding_photos\\";
File dir = new File(URL+aFile_to_add);
String[] files = dir.list();
It's working locally, but I obviously had to change the path from c://... to the above.
The full code is listed below in the addWedding Method
The method removes the .jpg from the file name and then writes the new file name to a database
Thanks for any insight.
Regards
Jim
public String addWedding(String aFile_to_add)
String feedback = "unset in scrubWedding";
try
String URL = "images\\wedding_photos\\";
Class.forName("org.gjt.mm.mysql.Driver");
java.sql.Connection connection = java.sql.DriverManager.getConnection("jdbc:mysql://localhost/rhwedd2_shop?user=**********&password=*******");
java.sql.Statement statement = connection.createStatement();
File dir = new File(URL+aFile_to_add);
String[] files = dir.list();
if (files == null)
feedback = "Sorry, couldn't find the file "+aFile_to_add+"...no files have been added.";
else
for (int i=0; i<files.length; i++)
// Get filename of file or directory
String filename = files;
String no_extension;
//convert string array element into a char array
char [] charsfilename = filename.toCharArray();
int newlength = charsfilename.length -4;
no_extension = String.valueOf(charsfilename,0,newlength);
filesAdded = filesAdded+", "+no_extension;
// Show the new file names in stack trace without extension
//System.out.println("String no_extension " + no_extension );
statement.executeUpdate("INSERT INTO items VALUES ('"+no_extension+"',5,'"+aFile_to_add+"')");
// write to table with item_id and weddingid
feedback = "The following files have been added..."+filesAdded;
if (statement != null )
statement.close();
if ( connection != null )
connection.close();
catch(Exception e)
feedback = "Into the catch";
e.printStackTrace(System.err) ;
return feedback;
}//end addWeddingString URL = "images\\wedding_photos\\";
File dir = new File(URL+aFile_to_add); ok, ok, I'll answer...
1) What gives you the impression that the relative directory "images\\..." exists (or, in other words, what makes you think your current directory is the parent of "images"? -
Hi,
When i try to read file from server,the following message is displayed .
ORA-29532: Java call terminated by uncaught Java exception: java.security.AccessControlException: the Permission (java.io.FilePermission /tmp read) has not been granted to EWMTRACKTEST. The PL/SQL to grant this is dbms_java.grant_permission( 'EWMTRACKTEST', 'SYS:java.io.FilePermission', ' /tmp', 'read' )
ORA-06512: at "EWMTRACKTEST.GET_DIRLIST_EWM", line 1
ORA-06512: at line 1
thanks and regards
P Prakashit seems obvious, user EWMTRACKTEST doesn`t have access to directory /tmp and the file under that.
try to give read permission and try again.
you could use command line like 'chmod' to grant permissions. -
Problem with loading XML file from directory.
Hello everyone.
*1)* I have directory defined by DBA. I have read, write privileges. I can read file from this directory using UTL_FILE, I can create file in this directory using UTL_FILE. I tried many times and it does not seem to be any problems.
*2)* I have very simple XML table (with just one column of xmltype). I can insert into this column using:
insert into temp_xml values (
Xmltype ('<something></something>')
*3)* When executing
insert into temp_xml values (
Xmltype (
bfilename('XML_LOCATION', 'sample.xml'),
nls_charset_id('AL16UTF8')
I'm receiving an error:
Error report:
SQL Error: ORA-22288: file or LOB operation FILEOPEN failed
ORA-06512: at "SYS.DBMS_LOB", line 523
ORA-06512: at "SYS.XMLTYPE", line 287
ORA-06512: at line 1
22288. 00000 - "file or LOB operation %s failed\n%s"
*Cause: The operation attempted on the file or LOB failed.
*Action: See the next error message in the error stack for more detailed
information. Also, verify that the file or LOB exists and that
the necessary privileges are set for the specified operation. If
the error still persists, report the error to the DBA.
*4)* Previously I was receiving more descriptive errors like permission denied, file not exists etc. This time there is no clear description apart from "file or LOB operation %s failed\n%s". I'm sure I can access this file in this directory (I used UTL_FILE to dbms_output the content).
Any help would be greatly appreciated.
Regards
Marcin JankowskiHi Marcin,
Welcome to the forums.
One very important thing with Oracle XML : please always give your database version, all four digits (e.g. 10.2.0.4).
Does the directory resides on the same machine as the database? Which OS?
Does any of the following work ?
DECLARE
v_lob CLOB;
v_file BFILE;
BEGIN
v_file := BFILENAME('XML_LOCATION','sample.xml');
DBMS_LOB.createtemporary(v_lob, true);
DBMS_LOB.fileopen(v_file);
DBMS_LOB.loadfromfile(v_lob, v_file, DBMS_LOB.getlength(v_file));
INSERT INTO temp_xml VALUES( xmltype(v_lob) );
DBMS_LOB.fileclose(v_file);
DBMS_LOB.freetemporary(v_lob);
END;
DECLARE
v_lob CLOB;
BEGIN
v_lob := DBMS_XSLPROCESSOR.read2clob('XML_LOCATION', 'sample.xml', nls_charset_id('AL16UTF8'));
INSERT INTO temp_xml VALUES( xmltype(v_lob) );
END;
/ -
Reading file from AS with details
Hi guys,
I want to read files from a directory on AS.
I used the FM SUBST_GET_FILE_LIST.
It works fine, but I'd like to know the file creation date.
I have to use this date time to decide which file I have to manage.
I thought the MTIME field was the answer, but it returns to me a number that I don't understand.
Any idea about it, or is there a FM that give to me the file creation date, modification date ecc
Regards
JampierreFrom the description MTIME is the Unix time - "last modification date, seconds since 1970"; Meaning this number is time in seconds from 1970; Did you check out the MOD_DATE and MOD_TIME fields in the same output table?
There are lot of threads in SDN regarding this and conversion of unix time to std date/time... please search in SDN,
Convert UNIX timestamp into Date and Time
Retrieve File creation date -
Reading files from Java embedding.
Dear All,
My BPEL process has a Java embedding node, and it invokes a Java class, in which an xsl file is being read for transformation.
I deploy the xsl files directory together with BPEL package (the jar). In the package, I put the file dir at the root level, which means the jar structure looks like the following:
/BPEL-INF
/META-INF
/xsd
/xsl
*.wsdl
*.bpel
bpel.xml
The java class is package in /BPEL-INF dir, it's supposed to read files from /xsl dir.
My question is, how should I put the file path?
I tried "/xsl/***.xsl" and "../xsl/***.xsl", neither works. Although "/xsl/***.xsl" worked when testing in JDeveloper, but FileNotFound after deployment.
Thanks,
HaiboI solved this issue by putting the files dir in /BPEL-INF/classes/. and use ClassLoader to read in those files.
-
Reading files from 10000 sub directories
I have to recursively read files from 10000 subdirectories. Each subdirectory might have 1000+ files. What would be the best way to read directories recursively ? Is there anything better than calling listFiles and then checking if it's a directory. I am planning to read 1000 files during one cycle.
Your hierarchy structure is nothing but a tree.
For example take this strucutre:
A
B C
F G D E
Each node is a directory and the leaf node is file.
You can use Post Order Traversal. That is Left-Right-Root. You can select any traversal technique. All you have to do is check that each element you are currently handling is a leaf node or not. -
Reading files from shared mapped folders
How is the correct approach to read files from a volume which maps a shared disk?
I mean, we have the Y:\Folder which maps \\bla_bla\root\folder.
Our application has to read into Y:\Folder.
How do we create a File object which points to Y:\Folder?
Thanks.> We catch a java.lang.NullPointerException
Okay. You know how to debug those, right? Some condition exists that is causing an NPE (that line alone won't do it), so you'll need to do some investigating.
How to resolve a java.lang.NullPointerException
You'll want to ensure that the directory actually exists, you've mapped it correctly, you have the appropriate permissions to access it, etc.
Good luck!
~
Maybe you are looking for
-
Can't open ALERT file error in 10G
We just converted to 10G 2 weeks ago. The alter file was where it was suppposed to be until a couple of days ago. Now I am getting this message and have no alert file. I have tried shutting down the db and restarting, to no avail. Archiving is workin
-
NPE in Oracle 9.2.0.1 setTimestamp
We recently encountered a situation where we got the following exception java.lang.NullPointerException at oracle.jdbc.dbaccess.DBData.clearItem(DBData.java:431) at oracle.jdbc.dbaccess.DBDataSetImpl.clearItem(DBDataSetImpl.java:3528) at oracle.jdbc.
-
I've got Logic Pro 7.3, and I've never had to create a rewire track before. Now that I've tried, I'm simply met with the message "No more tracks available". This is not different when I create a new project or start up an old one. Has anyone met this
-
Open browser window - not working right in different browsers
My client wants to link to a video on another company's site (he has permission). When I use the DW behavior of Open Browser Window in a specifc size it acts weird, depending on which broswer is used. I've used this function many times over the years
-
i don't want my data to be accessible outside the firewall, but need to be displayed on a web page If i generate an XML document of an oracle table, data changing daily, and use it to build an html page, does this assure that the data is safe? Where