Reading multiple charset based files
Hi !
I have a strange tricky problem :-). I have 6 different HTMLs with 6 different character set encodings (ShiftJIS, EUCJP, EUCKR, UTF-8 etc.,). I want to read them and copy over to another directory. I do not know the encoding before hand(there can be any number of files with any encoding). I used the following code but it just "bombs"? Any clue how I should do this?
-Sanjay
<pre>
public class TestWriter {
public static void main(String[] args) {
try {
InputStreamReader fin = new InputStreamReader(new FileInputStream(args[0]), "Shift-JIS");
OutputStreamWriter fout = new OutputStreamWriter(new FileOutputStream(args[0]+"_1"), "Shift-JIS");
int readIn = fin.read();
while (readIn != -1)
fout.write(readIn);
readIn = fin.read();
fout.close();
fin.close();
} catch(Exception e) {
e.printStackTrace();
</pre>
My guess is that the file you are reading is not SJIS and causing the program to throw an exception.
There is no easy way to do this but it is doable with some effort.
Similar Messages
-
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 multiple records in file adaptor
Hi,
I am trying to read records from one file and write them in another file.
But the thing happened is it ready and write only first record.
I check in the Audit... At receive it reads all three records, but in transform it takes only first record.
I have defined schema in inbound adaptor and used same for outbound.
Where should I make changes to read all the records from the input file.
Thanks,
KrunalI assume you are using a transform to do the mapping.
The trick here is to use the for-each function on the target mapping when the element repeats.
In the transformation design window right-click on the repeating element, choose the option for-each. This will create a new node just above. Map the source repeating node to the for each element.
Deploy and retest.
cheers
James -
Reading Multiple lines using File Adapter in PI 7.1
Hi Friends,
We are using PI 7.1 Service pack 4, scenario is File to IDOC .
I am using Sender File Adapter with File content conversion for fixed lengths to read file from FTP XI-SAP.
File Format :
EDI_DC40 , A, B, C, D, E
E1WPU01, F, G,H, I
E1WPU02 , J,K,L
E1WPU02 , J,K,L
I have maintained Fcc parameters . I am able to read files for mulitple rows when manually set the count in recorset structure
like :
Recordset Structure : EDI_DC40,1, E1WPU01,1, E1WPU02,2...
Problem is when I set * in Recorset Structure : EDI_DC40,1, E1WPU01,,E1WPU02,
Nothing is coming .
Could anyone help me how to resolve this issue.
Regards,
VijayHi Vijay,
As u mentioned in earlier post...
keyfieldName = TABNAM
EDI_DC40.fieldNames :
EDI_DC40. fieldFixedLengths:
EDI_DC40.keyFieldValue :
E1WPU01.fieldNames :
E1WPU01.fieldFixedLengths:
E1WPU01.keyFieldValue
E1WPU02.fieldNames :
E1WPU02.fieldFixedLengths:
E1WPU02.keyFieldValue
Here actually you are trying to get the key field value even from EDI_DC40 and E1WPU01 also....
So obviously u dnt have those values in that rows so.. it cannot get the rows....
So please u try this one..... The same FCC but remove the 2 lines.... for EDI_DC40 and E1WPU01
keyfieldName = TABNAM
EDI_DC40.fieldNames :
EDI_DC40. fieldFixedLengths:
E1WPU01.fieldNames :
E1WPU01.fieldFixedLengths:
E1WPU02.fieldNames :
E1WPU02.fieldFixedLengths:
E1WPU02.keyFieldValue
I hope this wil solve ur problem..
Lemme know if any issues...
Thanks & Regards,
H.L.Babu -
How to read Multiple sheet Excel file( One of the sheet generated by rule )
Hi Folks,
I have one critical requirement about reading an Excelsheet.
I have an Excelsheet, which has got 2 tabs. Now TAB1 is having the data stored and TAB2 has got data, which is created by some Rule using in Excelsheet.
Now when i am trying to pass this Excel sheet to Function module ' TEXT_CONVERT_XLS_TO_SAP' this Fucntion Module is returning the data from TAB1. But my requirement is that, i have to read data from TAB2, which is generated by implementing some rule on TAB1.
So Please help, me how can i read the multiple sheet Excel document and how to read the tab , which is generated by some rule.
Thanks.
PGHi Guru,
Thanks for your reply.
I have seen this blog, and treid to implement the code. But when i am caaling method GET_RANGES_DATA
in the program, it's hanging my whole program and followed by hanging my SAP login.
I have no clue, why my program is getting hung up, bcoz of this call.
After debugging this method, i found that the program is getting hung up at call of one function module DP_GET_TABLE.
This Function Module is internally called by above menthioned method.
So please let me know, if you have some input on above issue, or if you know some other way to implement this problem.
Regards
PG -
Is it possible through labview to set and read window¿s based file properties​?
Any file in XP operating system has file properties associated with it, such as, size, location, when the file was created, modified and last accessed. I know that Labview has the ability to access the size and modified property. Other file types such as image format types jpg, bmp and tif have additional associated properties such as: title, subject, author, and comments. Is it possible through labview to read and set these properties programmatically?
Hpopenoe wrote:
> Any file in XP operating system has file properties associated with
> it, such as, size, location, when the file was created, modified and
> last accessed. I know that Labview has the ability to access the size
> and modified property. Other file types such as image format types
> jpg, bmp and tif have additional associated properties such as: title,
> subject, author, and comments. Is it possible through labview to read
> and set these properties programmatically?
Well, you can most probably do that by calling Windows API functions.
Note however that the properties you mention are not generic Windows
file properties but file specific internal attributes. Explorer does at
least in XP handle some of those properties and shows them to the user
but does so with internal file type handlers to extract the properties
from the file.
I'm not sure those file type handlers are actually available for other
applications than Explorer without quite some work. If they are
available they are certainly not part of the standard Win32 API but most
probably part of the Windows shell component and I would guess not just
through normal API function calls, but through the shell namespace
enumeration, which is built on COM interfaces, something you only can
call from standard programming languages, most of them are done in C++
(and if you are a little more persistant in standard C).
So you are likely to need to either write your own DLL doing the nitty
gritty work of calling the shell interface and using that DLL in LabVIEW
or find an Active X component which does the work for you. No doubt
there is such an Active X component somewhere but how good and expensive
is always a big question.
Rolf Kalbermatter
Rolf Kalbermatter
CIT Engineering Netherlands
a division of Test & Measurement Solutions -
Best Practive - One mapping reading multiple source files
I want to develop a solution for one single mapping reading multiple similar source files that are stored on different directories on my OWB server. I want to be able to determine on runtime of my mapping from what location to load the source file from.
Example:
Mapping: Load_test_data
source file 1: c:\input\loc1\test.dat
source file 1: c:\input\loc2\test.dat
When I run the mapping I would like to use an input parameter specifying the location loc1 or loc2. I would also like to use this input parameter in my mapping to populate one column in my target table with the value of this input parameter. This design would make it possible to dynamically load source files from different directories and also being able to see after loading where the data came from.
Questions:
- Is there a way to create such a design
- If not, what alternative would be appropriate.
Thanks in advance for the feedbackThanks for the feedback. Unfortunately I do not use workflow together with my OWB.
I now indeed specified the file name and file location in the configuration of my mapping. However I am not able to change then upon executing the mapping. Data file name and file location are empty and greyed out when I execute my mapping. It always takes the values I specified in the configuration of my mapping
What I would like to do is specify the location upon runtime when I execute my mapping, but I don't know if this is possible. In addition I'd also want to use the data file location as an input parameter for one of the columns I populated in my target table.
Then in the end I would be able to use one mapping and read multiple sources files from different locations and also be able to check in the end where the data was loaded from.
Hope you can give me some more feedback on how to set this up in OWB.
Many Thanks!
data file name parameter to ma -
Read multiple files and write data on a single file in java
Hello,
I am facing difficulty that I want to read multiple files in java and write their data to a single file. Means Write data in one file from multiple files in java
Please help me out.
Naveed.algorithm should be something like:
File uniqueFile = new File();
for (File f : manyFilesToRead)
while (readingF)
write(dataFromF, intoUniqueFile); -
Hi everyone out there,
I would like to know how to read multiple files from same directory, but files hve different name, using java. Any help is appreciate, need asap..
Thnx,I want to process all the files that are in the
folder. Okay. This is the critical piece of information that you hadn't provided previously.
And you saying using loop? how do you propose
using loop for this?There are two different tasks: Identifying all the files, and processing each of them.
You definitely need a loop for processing them. That's what loops are for--doing the same thing multiple times.
You might or might not use a loop to identify the files.
I see two main possible approaches:
1) Provide the list of files as command line args when you start the VM, using your command shell's wildcard/globbing: java MyClass * Then inside your code: public static void main(String[] args) {
for (int ix = 0; ix < args.length; ix++) {
String fileName = args[ix];
// process it
} 2) Provide your class with the name of the directory you want to process (for instance as a command line arg). Create a java.io.File instance that corresponds to that directory. File has methods that list the files inside a diretory. Use that to get a list of the files, and run through that list. -
Read multiple text files and sort them
I am trying to read multiple text files and store the data from the file in vector.
but for days. I am with no luck. anyone can help me out with it? any idea of how to sort them will be appreciated.
Below is part of the code I implemented.
public class packet {
private int timestamp;
private int user_id;
private int packet_id;
private int packet_seqno;
private int packet_size;
public packet(int timestamp0,int user_id0, int packet_id0,int packet_seqno0, int packet_size0)
timestamp = timestamp0;
user_id=user_id0;
packet_id=packet_id0;
packet_seqno=packet_seqno0;
packet_size=packet_size0;
public void setTime(int atimestamp)
this.timestamp=atimestamp;
public void setUserid(int auserid)
this.user_id=auserid;
public void setPacketid(int apacketid)
this.packet_id=apacketid;
public void setPacketseqno(int apacketseqno)
this.packet_seqno=apacketseqno;
public void setPacketsize(int apacketsize)
this.packet_size=apacketsize;
public String toString()
return timestamp+"\t"+user_id+"\t"+packet_id+"\t"+packet_seqno+"\t"+packet_size+"\t";
}Here is the data from part of the text files. ( the first column is timestamp, second is userid, third is packetid.....)
0 1 1 1 512
1 2 1 2 512
2 3 1 3 512
3 4 1 4 512
4 5 1 5 512
5 6 1 6 512
6 7 1 7 512
7 8 1 8 512
8 9 1 9 512
9 10 1 10 512
10 1 2 11 512
11 2 2 12 512
12 3 2 13 512
13 4 2 14 512
14 5 2 15 512
15 6 2 16 512
16 7 2 17 512Here's a standard idiom for object-list-sorting:
/* cnleafdata.txt *********************************************
0 1 1 1 512
1 2 1 2 512
2 3 1 3 512
3 4 1 4 512
4 5 1 5 512
5 6 1 6 512
6 7 1 7 512
7 8 1 8 512
8 9 1 9 512
9 10 1 10 512
10 1 2 11 512
11 2 2 12 512
12 3 2 13 512
13 4 2 14 512
14 5 2 15 512
15 6 2 16 512
16 7 2 17 512
import java.util.*;
import java.io.*;
public class Packet implements Comparable<Packet>{
private int timeStamp;
private int userId;
private int packetId;
private int packetSeqno;
private int packetSize;
public Packet(int timeStamp0, int userId0, int packetId0,
int packetSeqno0, int packetSize0) {
timeStamp = timeStamp0;
userId = userId0;
packetId = packetId0;
packetSeqno = packetSeqno0;
packetSize = packetSize0;
public Packet(String timeStamp0, String userId0, String packetId0,
String packetSeqno0, String packetSize0) {
this(Integer.parseInt(timeStamp0), Integer.parseInt(userId0),
Integer.parseInt(packetId0), Integer.parseInt(packetSeqno0),
Integer.parseInt(packetSize0));
public Packet(String[] a){
this(a[0], a[1], a[2], a[3], a[4]);
public void setTime(int aTimeStamp){
timeStamp = aTimeStamp;
public void setUserId(int aUserId){
userId = aUserId;
public void setPacketId(int aPacketId){
packetId = aPacketId;
public void setPacketSeqno(int aPacketSeqno){
packetSeqno = aPacketSeqno;
public void setPacketSize(int aPacketSize){
packetSize = aPacketSize;
public int getUserId(){
return userId;
public String toString(){
return String.format
("%2d %2d %2d %2d %4d", timeStamp, userId, packetId, packetSeqno, packetSize);
public int compareTo(Packet otherPacket){
return userId - otherPacket.getUserId();
/* main for test */
public static void main(String[] args){
String line;
ArrayList<Packet> alp;
alp = new ArrayList<Packet>();
try{
BufferedReader br = new BufferedReader(new FileReader("cnleafdata.txt"));
while ((line = br.readLine()) != null){
// if (! recordValid(line)){
// continue;
String[] ar = line.split("\\s");
alp.add(new Packet(ar));
catch (Exception e){
e.printStackTrace();
System.out.println("[original]");
for (Packet p : alp){
System.out.println(p);
System.out.println();
Collections.sort(alp);
System.out.println("[sorted by user ID]");
for (Packet p : alp){
System.out.println(p);
} -
Multiple IDOCs based on multiple fields in File to IDOC mapping
Hello Experts,
I have a requirement to create multiple IDOCs based on multiple fields.
Earlier my requirement is to create IDOCs based on ShipID (i.e., for every ShipID new IDOC...I achieved this).
But now the requirement was to create IDOC based on two more fields like
Source:
ShipID1
FieldA with value1
FieldB with value1
Target :
1 IDOC to create
and If
Source:
ShipID1
FiledA with Value2
FiledB with Value2
ShipID1
FiledA with Value1
FiledB with Value2
Target:
2 IDOCs based on FiledA
Like wise IDOC should create for every change in FiledA and FieldB.
If FiledA and FiledB has no changes then create IDOC based on ShipID
please help me in achieving this as this is an urgent requirement.Hi Prasad -
Just concat all the three fields - shipID1, FieldA and FieldB and
remove contexts
split by value (value changed)
collapse contexts
This way whenever there is a change in any of the above fields you'll have separate IDOC.. -
How to read multiple files of different name using single file adapter
There are two inbound locations inbound1 and inbound2 , and the files structure present in these two inbound locations are same but the files start with different names example
(1)files in inbound1 starts with file1,file2...
(2)files in inbound2 starts with abc1,abc2...
by using same file adapter with read option how can i read both files....Hi K.A.N.N.,
You can define multiple directories using the above link in 11g and poll for the file as \*.*.
Alternatively you can use the Synchronous Read and specify the file name at runtime.
You can also use Pick activity to define multiple branches each with a File Adapter to read from a specified location with specified file name. Although it would contain multiple Adapter Definitions at Development-time, only one of the Adapters will execute at Run-Time.
Regards,
Neeraj Sehgal -
Unable to read multiple files in BODS
hi all,
i am unable to read multiple files [with same format of fields] using wild card characters in file name.
scenario:
i have 2 files: test1.xlsx & test2.xlsx
in the excel file format, for the file name column, i have given test*.xlsx.
and done the direct mapping to target column.
but when i run the job i am getting below error.
at com.acta.adapter.msexceladapter.MSExcelAdapterReadTable.ReadAllRows(MSExcelAdapterReadTable.java:1242)
at com.acta.adapter.msexceladapter.MSExcelAdapterReadTable.readNext(MSExcelAdapterReadTable.java:1285)
at com.acta.adapter.sdk.StreamListener.handleBrokerMessage(StreamListener.java:151)
at com.acta.brokerclient.BrokerClient.handleMessage(BrokerClient.java:448)
at com.acta.brokerclient.BrokerClient.access$100(BrokerClient.java:53)
at com.acta.brokerclient.BrokerClient$MessageHandler.run(BrokerClient.java:1600)
at com.acta.brokerclient.ThreadPool$PoolThread.run(ThreadPool.java:100)
please let me know if there is any solution to this.
regards,
SwethaHi,
i just copied a xlsx file with 3 different names (Test_Data.xlsx, Test_1.xlsx, Test_2.xlsx) and tried with below options and it worked for me.
Note: I tried on the same OS and DS 4.1 SP2(14.1.2.378)versions. In Linux File names are case sensitive. -
Reading Multiple lines in a file Using File Adapter
Hi All,
Iam new to this technology.How to read multiple lines in a file using file adapter.Brief me with the methodology.I didn't look at anything else but if you want to write more than one line ever to your file you should change this
out = new FileOutputStream("Calculation.log");to this...
out = new FileOutputStream("Calculation.log",true);A quick look at the API reveals the follow constructor FileOutputStream(File file, boolean append) append means should I add on the end of the file or over-write what is there.
By default you over-write. So in our case we say true instead which says add on to what is there.
At the end of that little snippet you shoudl be closing that stream as well.
So where you have
p.close();You should have
p.close();
out.close(); -
FTP Adapter to read multiple files from a directory. Not through polling.
Dear Friends,
I would like to know is it possible to configure the FTP adapter in Oracle BPEL 10.1.3.4 to read multiple files (different names, same structure) from a given directory. I do not want the BPEL to do a polling. Instead when I submit the BPEL process it should read all files from the directory.
I was looking at the option of Synchronous read but I am not able to specify wild card in the file name field. I do not know the file names at the time of reading.
Thanks for your help!Hi,
While you read the file, you can configure an adapter property in 'Receive'. This will store the filename, this filename can be used for sync read as the input parameter.
1. Create a message type variable called 'fileheader'. This should be of type Inboundheader_msg (whatever relevant Receive activity).
2. This variable will contain three parts - filename, FTPhost, FTPPort
3. Copy this fileheader to 'Syncheader'.
4. syncheader can be passed as an adapter proerty during sync read of the file.
During Receive and Invoke, you need to navigate to 'Adapter' tab to choose the created message type variable.
Let me know if you have further questions.
regards,
Rev
Maybe you are looking for
-
How to use digital trigger with analog I/O
How do I program analog input and/or analog output to start on a digital trigger (PFI pin) on PCI-4451/4551. I have tried out various configuration and succeeded in starting analog input, simultanuous input and output triggered by the the anlaog inpu
-
hello, using obiee 11g I have a requirement like this I have 2 prompts, begin date and close date as prompts,Depending upon the date selected i want to show or hide the column. By default i made the prompts to show current date and current_date-365 A
-
Want to read Field value set by Value help
Hello, I have BSP View which is using Value help extensions for one of the input. The search help is based on the Elementary Search Help which is further based on Z-Table. In my BSP view [IE] I am able to popup the Search help and able to select the
-
Questions about front end servers
Sun Java(tm) System Messaging Server 6.1 HotFix 0.11 (built Jan 28 2005) libimta.so 6.1 HotFix 0.11 (built 16:16:35, Jan 28 2005) SunOS mailstor1 5.9 Generic_112233-12 sun4u sparc SUNW,Ultra-4 On a multiple servers installation, is there a way to mak
-
Response time of a function module
Hi Friends, I'm creating a cutom program where i was using a BAPI ,which exist in other server. Now i want to record the response time of the BAPI , after placing the request in it and display the Time for the corresponding record in outp