Help reading file contents
Hi,
I have a file with these contents
�One�
Hello Man. h
�Two�
This is the body of the message, which can go on for as long as possible.
which can go on for as long as possible. This is the body of the message, which can go on for as long as possible. This is the body of the message, which can go on for as long as possible.
MessengerI am using this code to read the contents of the file
try
DataInputStream msgFile = new DataInputStream(new FileInputStream(fileName));
String str = "";
while((str=msgFile.readLine())!= null)
if(str.equalsIgnoreCase("�One�") )
String one = msgFile.readLine().trim();
if(str.equalsIgnoreCase("�To�") )
String two = msgFile.readLine().trim();
} When I try to print String "two", I get only
This is the body of the message, which can go on for as long as possible. as I am using readLine() method
Is there a way I can solve this problem to read until the end of the file?
Mathew
try something like this
BufferedReader in = new BufferedReader(new FileReader(fileName));
data = in.readLine();
while (data != null) {
// Here is your line, do what ever you want to do
data = in.readLine();
}
Similar Messages
-
Reading file content into internal table
Hi All,
I'm facing problem reading pdf file content into an internal table. I need to read this file from communication server (neither presentation nor application server). I have tried gui_upload , it is working fine but it does not work in batch jobs. Open dataset in binary mode is also not helping much. Could anyone help ?
Thanks a lot"open dataset <filepath> for input in binary mode" should work.... what does it say when you try this?
Thanks
Muktar -
Reading file content using Javascript
Hi Friends,
is it possibel to read the contents of the child window opened from a javascript.for example am opening a window using Window.open function in javascript, after opening the window can i read the contents ?If so how can anyone help in this.
Thanks
VishyBelow is the code of my normal java program which works fine.
try {
// File destFile = new File("./SourceFiles/savedFile.txt");
File destFile = new File("./SourceFiles/", "savedFile.txt");
BufferedWriter writer = new BufferedWriter(new FileWriter(destFile));
writer.write("TESTing File Save");
writer.flush();
System.out.println("SAVED!!");
} catch ( IOException e ) {
e.printStackTrace();
Structure of this project is
Samples
|SaveSample
|SaveSample.java
|SourceFiles
|savedFile.txt
I have implemented similar code in my servlet too. But this doesnt save the content to the HTML file.
protected void doPost(HttpServletRequest request,
HttpServletResponse response) throws ServletException, IOException {
action = request.getParameter("action");
try {
File destFile = new File("./SourceFiles/", "savedFile.html");
BufferedWriter writer = new BufferedWriter(new FileWriter(destFile));
writer.write(action);
writer.flush();
System.out.println("SAVED!!");
} catch ( IOException e ) {
e.printStackTrace();
Im getting FileNotFound Exception
java.io.FileNotFoundException: .\SourceFiles\savedFile.html (The system cannot find the path specified)
at java.io.FileOutputStream.open(Native Method)
at java.io.FileOutputStream.<init>(Unknown Source)
at java.io.FileOutputStream.<init>(Unknown Source)
at java.io.FileWriter.<init>(Unknown Source)
at savepackage.SaveContent.doPost(SaveContent.java:81)
Edited by: 849224 on Apr 5, 2011 4:17 AM -
Problem in reading file contents in to inernal table
i have a problem with the archive file
actually i have created archive files in SAP file system i stored the archive file in a external repository.
now i like to access one of the archive file i want to read the contents of the file in to a internal table.
the starting of the file contains some unique document number i need to able to capture that document number.
i am able to read the contents from archive file but the contents are unknown charecters.
i used open data set to read the contents of the file , but i cannot resolve these unknown charecters.Call transactions
- SARA Archive Administration
- AOBJ to find the read program (if exists) associated to the archive object
More information on [Archive Administration|http://help.sap.com/saphelp_smehp1/helpdata/en/8d/3e4d70462a11d189000000e8323d3a/frameset.htm] and [Archive Development Kit|http://help.sap.com/saphelp_smehp1/helpdata/en/2a/fa0391493111d182b70000e829fbfe/frameset.htm]
Regards,
Raymond -
Help required File Content Conversion.
Hi All,
Kindly help me in this topic i.e. File Content Conversion.
- What is File Content Conversion?
- Is knowledge of any programming language required?
- What is its function?
- How do I use it?
Thanks in Advance.
Regards,
Sreedhar, AvHi Sreedhar,
Reward points if this helps
What is File Content Conversion?
File content conversion is used for converting flat files (fixed lenght, comma seperated) into XML messages for further processing by an integration engine. The internal XI processing (mapping, routing etc) is based on XML messages hence you need messages to be converted to XML.
SAP By default understands xml data structure. If your file is coming in an xml format you can process it as it is.
In case of file that is coming with a delimiter then you need to have File content conversion for SAP adpater to conver file into an XML structure which will then go to next step of Message Mapping.
Is knowledge of any programming language required?
No
What is its function?
Check these blogs for content conversion,
/people/arpit.seth/blog/2005/06/02/file-receiver-with-content-conversion
/people/venkat.donela/blog/2005/06/08/how-to-send-a-flat-file-with-various-field-lengths-and-variable-substructures-to-xi-30
*How do I use it? *
http://help.sap.com/saphelp_nw04/helpdata/en/2c/181077dd7d6b4ea6a8029b20bf7e55/content.htm
Reward points if this helps
Regards
Pragathi. -
Need help in file content conversion complex structure
Hi Guys ,
Iam new to this file content conversion , Please let me know whether below requirement is possible .if yes than how ?
Inbound XML file from Proxy
<Data>
<keyfield1>0011</keyfield1>
<keyfield2>0012</keyfield2>
<Keyfield3>0013</Keyfield3>
<field1>Test1</field1>
<field2>testfield1</field2>
<field3>0001</field3>
<Data>
<keyfield1>0021</keyfield1>
<keyfield2>0022</keyfield2>
<Keyfield3>0023</Keyfield3>
<field1>Test2</field1>
<field2>testfield2</field2>
<field3>0002</field3>
output pgp flat file .
pgp file format should be as below after file content conversion
0011|0012|0013|Test1||||||
0011|0012|0013|Testfield1||||||
0011|0012|0013|0001||||||
0021|0022|0023|Test2||||||
0011|0012|0013|Testfield2||||||
0011|0012|0013|0002||||||
thanks a lot .
Regards
PrabhuHi.
Try this.
First you need to use a message mapping and create a target structure to convert a similar output structure that do you want. like this
<Target>
-- Field1
-- Field2
-- Field3
-- Field4
-- Field5
-- Field6
-- Field7
-- Field8
-- Field9
</Target>.
Then map
keyfield1-> Field 1 ,keyfield2-> Field 2 , keyfield 3---> Field 3
map field1-> field4 .. for the others fields duplicate the Target node (right click) and map map field2-> field5 ..etc.
For the field 5 until field 9 map with constant ("'')
Then in you receiver comunication channel put simple parameters.
Target.fieldSeparator = |
Target.endSeparator = 'nl'
Regards. -
How to add do not read file content option inside File Adapter (Synch Read)
Hi,
Is there any way, that I can skip reading the file content inside file adapter with operation as Synchronous Read ( I just want to read the file name and directory and if the file name matches with the input variables then I have to delete the files, for this i am using FA with synch read operation, everything is fine like deletion, but it is reading the file content and storing it in DB, i dont want this) .This will solve your problem.
http://docs.oracle.com/cd/E23943_01/integration.1111/e10231/adptr_file.htm#CHDHIEBI
HTH.
Puneet. -
WebDynpro: How to read file content?
Hi,
My business scenario requires:
1, The file name is passed in through inbound plug parameter
2, I need to read the file content and then attach it to my CRM transaction
Please share with me how to read the file content.
The following approaches do not fit my scenario:
1, UI element: FileUpload
The reason is obvious: there is only file name parameter instead of any UI interface
2, Function Module: GUI_UPLOAD
The reason is that dump will happen in WebDynpro environment
Thanks & Best Regards,
DavidHI,
Refer these links -
Get content document in WD abap
Excel File to Internal Table -
Read file content and keep binary copy
Hi All, I don't know what the best way of doing this is, but my requirement is to read the content of a file using File Adapter and post a document with this datda in SAP, but also to keep a binary copy of the file attached to the posted document.
So my question is, Is there a way within the file adapter to read the content of the file using the Content Conversion mechanism and at the same type keep a binary copy of the read file.
Thanks,
PabloHi,
I know we can send it via proxy but your question was something different or my be I misunderstood it.. here is your question again..
>
Pablo Lopez wrote:
> Hi All, I don't know what the best way of doing this is, but my requirement is to read the content of a file using File Adapter and post a document with this datda in SAP, but also to keep a binary copy of the file attached to the posted document.
> So my question is, Is there a way within the file adapter to read the content of the file using the Content Conversion mechanism and at the same type keep a binary copy of the read file.
>
> Thanks,
> Pablo
What I understood from your question that, there is a file which you want to read/pick via file adapter and at the same time you also want to attach same file along with the content and then post it to R3.
If my assumption is correct then it is not possible. Yeh If there is some workaround then that is different story.
Regards,
Sarvesh -
Reading and writing to file , getting null when i try to read file content
i start by apologizing incase i have posted this question in the wrong forum
i am trying to iterate through a directory tree and pick all the subdirectories and put them in an arraylist . on the other hand , i am picking all the files and putting them in a different arraylist . After that i iterate through the arraylist , pick a folder , create a file in it search for all the files of the same type in its subfolders and write them to the newly created file
The problem i am running into is i i can't read the files and hence i can't write to the file .
My directory tree is in the format
c:\KPCData\\01\01\01\01\01\ file1_type1
c:\KPCData\\01\01\01\01\02\ file2_type1
where one one of the types is "covers" . i know this could be asking too much but i am at my tethers end , could someone please have a look at the code and tell me where i might be going wrong . you could zero in on the part where i have ************ before the a line of code thank you package directories;
import java.io.*;
import java.util.*;
public class Directories {
private static ArrayList direcs= new ArrayList();
private static ArrayList census= new ArrayList();
private static ArrayList vagrant= new ArrayList();
private static ArrayList hotel= new ArrayList();
private static ArrayList emigrant= new ArrayList();
private static ArrayList traveller= new ArrayList();
private static ArrayList longform= new ArrayList();
private static ArrayList cover= new ArrayList();
private static String parentPath = null;
private static File mycover = null;
private static File mytravel = null;
private static File myemigrant = null;
private static File mylong= null;
private static File myinstitution = null;
private static File myvagrant = null;
private static BufferedReader in;
private static BufferedWriter out;
private static String read,toread;
//function for listing the folder contents
class compareDirs implements Comparator
public int compare(Object one, Object two)
int val=0;
File file1 = (File)one;
File file2= (File)two;
String name1 = file1.toString();
String name2= file2.toString();
if (name1.length()==name2.length())
val= name1.compareTo(name2);
else
if( name1.length()>name2.length())
val=-1;
if (name1.length()<name2.length())
val=1;
return val;
private ArrayList recurs(File dir,File file) throws IOException
File []files=dir.listFiles();
for(int index=0;index<files.length ;index++)
if(files[index].isDirectory())
recurs(files[index],file);
}//if
else
census.add(files[index]);
}//for index
return census;
} //recurs
//function for determining the number and paths of the folders
private ArrayList numDirs(File dirs)
File []files=dirs.listFiles();
for(int index=0;index<files.length ;index++)
if(files[index].isDirectory())
if (direcs.contains(files[index])==false)
direcs.add(files[index]);
numDirs(files[index]);
}//if
}//for index
return direcs;
public static void main(String[]args) throws IOException
File myfile = new File("C:\\KPCData");
File myfile2= new File("C:\\KPCData\test.txt");
Directories dir = new Directories();
if (myfile.isDirectory())
ArrayList myList=dir.recurs(myfile,myfile2);
ArrayList mydir1 = dir.numDirs(myfile);
ArrayList mydirs = new ArrayList();
mydirs.add(mydir1.get(0));
for (int x=0;x<mydir1.size();x++)
{ int count=0;
for (int y=0;y<mydirs.size();y++)
if (x==y)
count++;
if (count<1)
mydirs.add(mydir1.get(x));
Collections.sort( mydirs,dir.new compareDirs() );
for(int index1 =0 ;index1<mydirs.size();index1++)//print out directories
File mydir=(File)mydirs.get(index1);
File directory= (File)mydirs.get(index1);
if(!mydir.getPath().contains("00"))//// if not leave node create files for each file type
String name1 =mydir.getPath();
ArrayList ray=new ArrayList();
String name="K";
for (int index=0;index<name1.length();index++ )
if (name1.charAt(index)!='\\'&&name1.charAt(index)!='C'&&name1.charAt(index)!=':'&&name1.charAt(index)!='K'&&name1.charAt(index)!='P'&&name1.charAt(index)!='D'&&name1.charAt(index)!='a'&&name1.charAt(index)!='t')
name =name+(String.valueOf(name1.charAt(index)));
// create a string
name= name.substring(1);
String trial = name+"_cover.dat";
mycover = new File ( mydir,trial);
if (mycover.exists()) {
mycover.delete();
mycover.createNewFile();
} else {
mycover.createNewFile();
String addit = mydir.getParent().toString();
mylong = new File (addit+"\\_long.dat");
if (mylong .exists()) {
mylong.delete();
//mylong.createNewFile();
} else {
//mylong.createNewFile();
myemigrant = new File (mydir.getParent()+"\\_emigrant.dat");
if (myemigrant.exists()) {
myemigrant.delete();
// myemigrant.canWrite();
} else {
// myemigrant.canWrite();
mytravel= new File (mydir.getParent().toString()+"\\_traveller.dat");
if (mytravel.exists()) {
mytravel.delete();
// mytravel.createNewFile();
} else {
//mytravel.createNewFile();
myinstitution = new File (mydir.getParent().toString()+"\\_institution.dat");
if (myinstitution.exists()) {
myinstitution.delete() ;
// myinstitution.createNewFile();
} else {
//myinstitution.createNewFile();
myvagrant = new File (mydir.getParent().toString()+"\\_vagrant.dat");
if (myvagrant .exists()) {
myvagrant.delete();
// myvagrant.createNewFile();
} else {
//myvagrant.createNewFile();
//}//initial
for( int index2 =0;index2<myList.size();index2++)//loop the second one for individual files
File file= (File)myList.get(index2);
if (file.getParent().contains("00"))//leave node
parentPath =file.getParent().substring(0, file.getParent().length()-4);
else
parentPath =file.getParent().substring(0, file.getParent().length()-3);
if (parentPath.toString().compareTo(directory.getParent())==0&file.getName().contains("cover"))
try {
in = new BufferedReader(new FileReader(file));
out = new BufferedWriter( new FileWriter(mycover));
************ while ((read =in.readLine())!=null)
System.out.println("testing");//test whether i ever get in this section !!!
out.write(read);
out.close();
in.close();
catch(NullPointerException e)
System.out.println(e);
catch(IOException e)
System.out.println("There was a problem:" + e);
}//class Directorieskingspalace wrote:
Dr Clap
The problem i am having is that whereas i am very sure that there are contents in the files i am trying to read , this part of the code Print the Values of parentPath,directory.getParent() and file.getName() here .In the start of this if condition to get a idea what stuff is coming here.
if (parentPath.toString().compareTo(directory.getParent())==0&file.getName().contains("cover"))
{Are you trying to compare parentPath and directory.getParent() as Strings ? How about using equals() ?
Also are you aware that a single & and && are not one and the same ?
& will check nevertheless even if the string comparison on the parentPath returns true or false.
&& will not check file.getName() part if the String comparison part fails.
try {
in = new BufferedReader(new FileReader(file));
out = new BufferedWriter( new FileWriter(mycover));
************ while ((read =in.readLine())!=null)
System.out.println("testing");//test whether i ever get in this section !!!
out.write(read);
out.close();
in.close();
catch(NullPointerException e)
System.out.println(e);
catch(IOException e)
System.out.println("There was a problem:" + e);
}How about adding a simple Exception catch block here ,in case you miss anything ?
never gets executed executed (meaning ,according to the code, the files am reading have no content ). i am a bit new to files and directories in java . i am hence seeking advice on what i could be doing wrong .IN short,debugging your code will help you a lot. -
Need help reading file directory from applet!
Hi i am writing a java applet which has to read in several text files from its codebase directory. I have this code at the moment which causes a nullpointerexception:
public void initTables()
File dir = new File(getCodeBase().getPath());
File[] files = dir.listFiles();
for (int i = 0; i < files.length; i++)//null pointer here
String fileName = files.getName();
if(fileName.endsWith("set.txt"))
fileName = fileName.substring(0, (fileName.length() - 4));
Table t = new Table(this, fileName);
}Anybody know whats going on here?
thanksSorry i thought it was a null pointer, it's actually this:
java.security.AccessControlException: access denied (java.io.FilePermission C:\Users\Emud\Documents\pokemon read)
at java.security.AccessControlContext.checkPermission(Unknown Source)
at java.security.AccessController.checkPermission(Unknown Source)
at java.lang.SecurityManager.checkPermission(Unknown Source)
at java.lang.SecurityManager.checkRead(Unknown Source)
at java.io.File.list(Unknown Source)
at java.io.File.listFiles(Unknown Source)
at Gui.initTables(Gui.java:75)
at Gui.init(Gui.java:16)
at sun.plugin2.applet.Plugin2Manager$AppletExecutionRunnable.run(Unknown Source)
at java.lang.Thread.run(Unknown Source)
Exception: java.security.AccessControlException: access denied (java.io.FilePermission C:\Users\Emud\Documents\pokemon read)
yeah, i'm making a program about pokemon...cos i'm cool 8) -
Need help reading files from a simple applet
hi everyone,
i have the following problem while trying to read from a file:
java.security.AccessControlException: access denied (java.io.FilePermission dr.xml read)
this problem shows up only when loading applet from a browser... if i use appletviewer everithing is ok.
this is the code:
cycle = new String[2];
phase = new String[8];
v = new Vector();
int temp;
try {
try {
fis = new FileInputStream("dr.xml");
while ((temp = fis.read()) > 0) {
buf += (char) temp;
fis.close();
fis = null;
} catch (java.io.FileNotFoundException ex) {
System.out.println("File does not exist. ");
} catch (java.io.IOException ex) {
System.out.println("error. ");
ex.printStackTrace();
}thanksYou don't have access to the file system. Think about it, you visit a web page and an applet starts reading your files? That's a HUGE security risk.
That said, I think you can do this if you have a signed/trusted applet. Google "signed applets" and "certificates" -
I put my DES key in a text file and stored within one of the java source folder like com.xyz.order.file.key
how do I read this file? It's saved in local hard drive. Thanks.Either the path is wrong or the desired resource is actually not in the classpath.
That said, why are you reading it into a fixed length byte array? Is that file always 16 bytes long?
Still, the aforementioned IO tutorial is really worth reading. For sure in your case. Go read it. -
Hi, could any one give me some tips on how to fill this array from a file (data.txt) on the computer that reads:
50 99 44 35 37 22 12 19 7 44
77 64 23 52 59 62 85 98 5 100
72 70 60 50 43 30 20 10 91 1
11 31 81 98 61 13 21 25 44 10
The values are 1-100 but the program's array should have 10 spots. This is what I have so far but I'm confused about what I'm doing:
public static void main(String[] args)
EasyReader console = new EasyReader();
final int MAX = 100;
int [] values = new int [MAX];
int [] numberValues = new int [10];
// EasyReader File23 = new EasyReader("D:\\data.txt");
// String value= File23.readLine();
//System.out.print(value);
int logicalLength;
logicalLength = fillArray(numberValues);
System.out.print(logicalLength);
public static int fillArray(int []numberValues)
EasyReader File23 = new EasyReader("D:\\data.txt");
int LL = 0;
int xy= File23.readInt();
while (!File23.eof())
numberValues[LL] = xy;
LL++;
xy = File23.readInt();
File23.close();
return LL;
}thanks for the tip:
Any tips on how to fill this array from a file (data.txt) on the computer that reads:
50 99 44 35 37 22 12 19 7 44
77 64 23 52 59 62 85 98 5 100
72 70 60 50 43 30 20 10 91 1
11 31 81 98 61 13 21 25 44 10
The values are 1-100 but the program's array should have 10 spots. This is what I have so far but I'm confused about what I'm doing (there is an exception in the main too):
public static void main(String[] args)
EasyReader console = new EasyReader();
final int MAX = 100;
int [] values = new int [MAX];
int [] numberValues = new int [10];
int logicalLength;
logicalLength = fillArray(numberValues);
System.out.print(logicalLength);
public static int fillArray(int []numberValues)
EasyReader File23 = new EasyReader("D:\\data.txt");
int LL = 0;
int xy= File23.readInt();
while (!File23.eof())
numberValues[LL] = xy;
LL++;
xy = File23.readInt();
File23.close();
return LL;
} -
How to read a file content from portal
Hi experts,
I have a file (xml or xlsx), which i have kept in D drive.
then using GUI_UPLOAD, i have read file content into internal table. then i am proceeding furthur.
but in real, my file will be in portal (means https:\\in.xyz.com\........\TEST.XML
in this case i can not use GUI_UPLOAD.
can any one suggest how can i achieve above. Thanks.
Regards,
Venkata PrasadHi venkata
try this code below
tables: znks_exceldb.
types: begin of wa_input,
emp_id type string,
name type string,
middle type string,
last_name type string,
address type string,
acc_num type string,
mobile type string,
end of wa_input.
data: gt_intern type kcde_intern.
data:gwa_intern type kcde_intern_struc.
data gt_input type table of wa_input.
data gwa_input like line of gt_input.
data it_tab type table of znks_exceldb.
data it_wa like line of it_tab.
constants c_seprator type c value ','.
parameters ex_file type localfile obligatory.
at selection-screen on value-request for ex_file.
call function 'F4_FILENAME'
* EXPORTING
* PROGRAM_NAME = SYST-CPROG
* DYNPRO_NUMBER = SYST-DYNNR
* FIELD_NAME = ' '
importing
file_name = ex_file.
start-of-selection.
perform readfile using ex_file.
perform insert.
perform display.
form readfile using ex_file type localfile.
data:lv_filename type rlgrap-filename.
data: lv_index type i.
field-symbols: <> type any.
lv_filename = ex_file.
call function 'KCD_CSV_FILE_TO_INTERN_CONVERT'
exporting
i_filename = lv_filename
i_separator = c_seprator
tables
e_intern = gt_intern
exceptions
upload_csv = 1
upload_filetype = 2
others = 3.
if sy-subrc <> 0.
* Implement suitable error handling here
endif.
loop at gt_intern into gwa_intern.
move gwa_intern-col to lv_index.
assign component lv_index of structure gwa_input to <>.
move:gwa_intern-value to <>.
at end of row.
append gwa_input to gt_input.
clear gwa_input.
endat.
endloop.
endform.
form insert.
loop at gt_input into gwa_input.
it_wa-emp_id = gwa_input-emp_id.
it_wa-name = gwa_input-name.
it_wa-middle = gwa_input-middle.
it_wa-last_name = gwa_input-last_name.
it_wa-address = gwa_input-address.
it_wa-mobile = gwa_input-mobile.
it_wa-acc_num = gwa_input-acc_num.
append it_wa to it_tab.
endloop.
insert znks_exceldb from table it_tab accepting duplicate keys.
endform.
form display.
loop at gt_input into gwa_input.
write :/ gwa_input-emp_id,
gwa_input-name,
gwa_input-middle,
gwa_input-last_name,
gwa_input-address,
gwa_input-mobile,
gwa_input-acc_num .
endloop.
endform.
Regards
Niraj Sinha
Maybe you are looking for
-
I downloaded town of salem off steam, when i tried to run it it said i needed to get/update adobe air, so i though thats not too hard, when i procceded to download it and install it a message came up saying "An error occurred while installing Adobe A
-
So I was downloading albums for my phone on the macbook pro and I tried putting in the charger for my phone but i had it in reverse and when i tried putting it in it just completely turned off. When i connected it to the charger the light on the char
-
Remove Saved Search functionality from Web IC
Hi Experts, I have a view where in there is a component related to Saved Searches functionality that is appearing on the Web IC. Now, for my client, they do not want those fields to be visible. So, I wanted to know how can those fields related to Sav
-
Hello, I am trying to delete the line item is PO against which i have done GR,IR & 922-Rejection & rejection invoice. While delecting system shows as error as " difference b/w GR & IR qty" Plz suggest.
-
Missing fonts in .folio
I just updated my app for ios8 and my fonts aren't showing up. Does this have anything to do with CC and Typekit?