Appending data in file ?
Hi,
I have a question. I'm trying to append data in a file. But it is not ? I don't know why it is not appending. Can you please look at my code.
Here what am i doing that calling different methods in the child class from parent class by giving different options. Here i'm giving input from the commandline.
here is my sample code
import java.io.*;
public class AppendFile{
public static void main(String[] args) throws IOException,EOFException
try{
// creating file and appending data
BufferedReader in = new BufferedReader(new InputStreamReader(System.in));
PrintWriter out = new PrintWriter( new FileWriter("out.txt",true));
ClassA a = new ClassA(out);
for(;;)
System.out.println("Enter no :");
int number = Integer.parseInt(in.readLine());
out.println(" ENTER NUMBER FROM CATALOG : "+number);
if ( number == 1)
a.method1(); // calling ClassA - method1
}else if( number == 2)
a.method2(); // calling ClassA - method2
}else
System.exit(-1);
out.close(); // closing PrintWriter out
}catch(EOFException eofe)
System.out.println(" "+eofe);
catch(IOException ioe)
System.out.println(" "+ioe);
// child class
class ClassA{
PrintWriter out;
public ClassA(PrintWriter out1)
out = out1;
public void method1()
System.out.println(" ClassA- method1");
out.println(" ClassA- method1");
public void method2()
System.out.println(" ClassA- method2");
out.println(" ClassA- method2");
}Can you please look at code and give suggestions to me.
Thank you,
-balaji
You should try your own code.
Here is an example that could work, with minor changes on your original code above.
import java.io.*;
public class AppendFile{
public static void main(String[] args){
BufferedReader in=null;
PrintWriter out=null;
try{
in = new BufferedReader(new InputStreamReader(System.in));
out = new PrintWriter( new FileWriter("out.txt",true));
ClassA a = new ClassA(out);
for(;;){
System.out.println("Enter no :");
int number = Integer.parseInt(in.readLine());
out.println(" ENTER NUMBER FROM CATALOG : "+number);
if ( number == 1) {
a.method1();
}else if( number == 2){
a.method2();
}else{
throw new IllegalArgumentException("input has unexpected values");
}//end of for
}catch(EOFException eofe) {
System.err.println(" "+eofe);
}catch(IOException ioe){
System.err.println(" "+ioe);
}catch(IllegalArgumentException argex){
System.err.println(argex.getMessage());
}finally{
System.out.println("Reader ane Writer will be closed");// testing output
try{
if(in!=null) in.close();
if(out!=null) out.close();
}catch(IOException ioe){;}
}
Similar Messages
-
Appending data in dumpfile paremeter in exp command
Hi,
I have 10.2.0.1 installed on windows 2003 server.
I have taking hot backup using command.
Exp username/pwd FILE=C:\DataBaseBackups\3AMNEO.DMP LOG=C:\DataBaseBackups\3AMNEO.LOGwhich is working fine.
I made a batch file which have this code and this execute daily on a particular time and overwrite existing (i.e. last day) backup. But i don't want to do so.
I want to append data with file name so that every day it creates a new backup. (Do not over write existing backup.)
my aim is to take daily backup without overwrite existing backup automatically.
ThanksHi,
First thing is that Taking Export Based Backup is not the Consistent and not a valid Backup and not treated as Hot Backup. I suggest you not the follow this method.. !!
If my way of understanding is Correct If you are thinking about Cumulative Option that might work out
where An cumulative export backs up only the tables that have changed since the last cumulative.
For tht use the Options
FILE= cumulative01009.dmp
LOG= cumulative01009.dmp
INCTYPE=CUMULATIVE
I apologize I understood your question in different way.. !!
- Pavan Kumar N
Edited by: Pavan Kumar on Oct 4, 2008 4:16 PM -
Append the data in file at receiver side
Hi All,
I want dump the data frm SAP tables. the data is hughe so we are sending the data in slots from ECC like 50K recoerds at a time and after that to collect that i using the append parameter at file receiver side and records are getting appended in file only that is correct
but my one doubt is
let say monday the records get append into file at receiver side and on tuesday again the records will get appended in same file....it will be problem for this i used create parameter with overrite my question if i am using create then we can not use append ........
please suggest...........
RegardsHi gangadhar,
Append will work like this..
if there is no file ..create the file and if file already exists then appends the data to the existing file..
in your case when you create the file with day i.e file_day ..first time when you send 50K records file will get created..
if you send another 50k in the same then will get appended to the same...
in case if you send the another 50K set another day..then a new file will get create as there is no file available with taht file name
i.e filename_nextday...
Hope this clears all your queries
HTH
Rajesh -
How can we append data in existing flat file
how can we append data to a existing flat file (Text file).
just fill the itab from data which suppose to append to text file.than read text file from GUI_UPLOAD and loop on itab and with the use of read statements you may append the data.
-
Appending data(Image and Text) to a file written with RTFWriter2.
I have file witten using RTFWriter2 which contains image and text.I nedd to modify the contents of that file at runtime through browsing and selecting the JFileChooser and append the data to existing selected file.
I write inot the file for the first time using FileOutputStream("filename",ture)
where true stands for appending data to current file,if does noes have any/not.
But this does not work when i write the file using RTFWriter2,and i have to use this RTFWriter2 b'coz writing an image to a file is not done by any other way.
If there is any do let me know and if not then what is the solution to this problem of appending data to existing file written by RTFWriter2.
Your repkeis will be appreciated.Thank You.Mubin_Ahmed wrote:
Hi,
I want to write an application which can be used to read a file that contains both images and text.
It must separate the images and text and write them in separate files..
Can anyone help me with this please...
My email id is [email protected]
Thanks in advance...This forum is to use as a resource for your questions, not a place to enlist someone to program for you. If you have specific questions on what to do, not: "I've not a clue, so explain the wold to me." But specific questions on how to get your code to work or points about Java, then people from all over the world will be happy to help you in the context of the forum, and not through your private e-mail. E-mail defeats the basic purpose of having public forums for learning and exchange of information. -
Append data into the file in application server
Hi Friends,
I have an issue where i have a job which has three different stepst for same program. If i run the job the program will create a file in the application server and append the other two steps in the same file without overwriting the file or creating a new file.
My problem is like its creating three different files in application server for that particular job since it has three steps . Its not appending into one particular file .
I am using the FM 'Z_INTERFACE_FILE_WRITE' where i have used the pi_append in the exportng parameter . ITs working when i specify the file in local system. It is appending correctly when i run the report normally to apppend into local system.
But when i schedule a job to append the file in application server its creating three different files.
Kindly help me if anyone is aware of this issue
Thanks in advance
KishoreHi,
Please use open dataset to write and append files.Please check the logic of Z FM which you are using .
To open and write into a file use
OPEN DATASET FNAME FOR OUTPUT.
To append data into existing file use
OPEN DATASET FNAME FOR APPENDING.
To write into file:
v_file = file path on application server
OPEN DATASET v_file FOR output.
IF sy-subrc NE 0.
write:/ 'error opening file'.
ELSE.
TRANSFER data TO v_file.
ENDIF.
CLOSE DATASET v_file.
For appending :
OPEN DATASET v_file fOR APPENDING.(file is opened for appending data position is set to the end of the file).
Thanks and Regards,
P.Bharadwaj -
How to append data from different import files?
Dear experts,
The customer is having different applications running that will output imports files BPC needs at a different time of process. Is it possible to append data which already exist in BPC from import?
eg. BPC already has a record
Factory1, Actual, 2008.OCT, Movement1, 30
import file-
Factory1, Actual, 2008.OCT, Movement1, 100
and I need to add them up to become 130.
Looks like regular import will only replace the original record by the new imported value. I'm still trying...
Thanks a lot,
Jim HsuI do not think there is a way to use a standard import package to perform this action. Typically when you are importing, you are saying this is the new value. Not increment/decrement the value.
I have never had to implement a solution for a problem like this. However, I would write a custom SSIS package that would extract the BPC data for the same dimensionality being imported and append it with the import file, then import the combined file. Values sharing the same dimensionality in the same import file are aggregated on the actual import.
SO your input file has 30, the export gets 100, the combined file has both and the actual value imported would be 130.
That would be the approach I would take, but others might have more experience in different areas. -
Append data to a existing file thru ALSB Service
Hi,
I want to write/append message data to a file before and after I invoke a Business Service.
I have created a Business Service with Service Type as Messaging Service and the protocol as FILE. I notice that everytime I call the Business Services a new text file is created. Is there a way I can append messages to the same file.
The workaround I thought of is to write a Java Class to write/append data to a file and invoke this as a Java Callout. Is this a feasible/good solution.
If anybody has any ideas of implementing this, please help.
Thank you.This feature is not supported by ALSB
You are correct, your best bet is to write some code in a Java callout to implement your expected behavior.
Gregory Haardt
ALSB Prg. Manager
[email protected] -
Can I append date to the file name using Bursting
Hi All,
I know that we can append date to the file using %y, %m and %d for
Email
FTP
WEBDAV
But is there any way of appending the date to the file name if I am bursting my file to a shared location.
I tried that %y, %m and %d but that doesn't work for bursting.
Please reply
Thanks,
RonnyIf this requirment is for EBS, please refer the following blog
http://blogs.oracle.com/BIDeveloper/2010/08/xdoburstrpt_passing_parameters.html
For standalone see the following delivery sql query as example.
select
d.department_name KEY,
'Standard' TEMPLATE,
'RTF' TEMPLATE_FORMAT,
'en-US' LOCALE,
'PDF' OUTPUT_FORMAT,
'FILE' DEL_CHANNEL,
'C:\Temp' PARAMETER1,
d.department_name||'_'||to_char(sysdate,'mmddyyyy')|| '.pdf' PARAMETER2
from
departments d
Thanks
Ashish -
" Can not interpret the data in file " error while uploading the data in DB
Dear All ,
After running the below report I am getting the " Can not interpret the data in file " error.
Need to upload the data in DB through excel or .txt file.
Kindly advise to resolve the issue.
REPORT ZTEST_4.
data : it like ZPRINT_LOC occurs 0 with header line,
FILETABLE type table of FILE_TABLE,
wa_filetable like line of filetable,
wa_filename type string,
rc type i.
CALL METHOD CL_GUI_FRONTEND_SERVICES=>FILE_OPEN_DIALOG
CHANGING
FILE_TABLE = filetable
RC = rc.
IF SY-SUBRC = 0.
read table filetable into wa_filetable index 1.
move wa_filetable-FILENAME to wa_filename.
Else.
Write: / 'HI'.
MESSAGE ID SY-MSGID TYPE SY-MSGTY NUMBER SY-MSGNO
WITH SY-MSGV1 SY-MSGV2 SY-MSGV3 SY-MSGV4.
ENDIF.
start-of-selection.
CALL FUNCTION 'GUI_UPLOAD'
EXPORTING
FILENAME = wa_filename
FILETYPE = 'ASC'
HAS_FIELD_SEPARATOR = 'X'
TABLES
DATA_TAB = it.
IF SY-SUBRC = 0.
Write: / 'HI'.
MESSAGE ID SY-MSGID TYPE SY-MSGTY NUMBER SY-MSGNO
WITH SY-MSGV1 SY-MSGV2 SY-MSGV3 SY-MSGV4.
ENDIF.
insert ZPRINT_LOC from table it.
if sy-subrc = 0.
commit work.
else.
rollback work.
endif.
Regards
Machindra Patade
Edited by: Machindra Patade on Apr 9, 2010 1:34 PMDear dedeepya reddy,
Not able to upload the excel but have sucess to upload the .csv file to db through the below code. Thanks for your advise.
REPORT ZTEST_3.
internal table declaration
DATA: itab TYPE STANDARD TABLE OF ZPRINT_LOC,
wa LIKE LINE OF itab,
wa1 like line of itab.
variable declaration
DATA: v_excel_string(2000) TYPE c,
v_file LIKE v_excel_string VALUE 'C:\Documents and Settings\devadm\Desktop\test.csv', " name of the file
delimiter TYPE c VALUE ' '. " delimiter with default value space
read the file from the application server
OPEN DATASET v_file FOR INPUT IN TEXT MODE ENCODING DEFAULT.
IF sy-subrc NE 0.
write:/ 'error opening file'.
ELSE.
WHILE ( sy-subrc EQ 0 ).
READ DATASET v_file INTO wa.
IF NOT wa IS INITIAL.
append wa TO itab.
ENDIF.
CLEAR wa.
ENDWHILE.
ENDIF.
CLOSE DATASET v_file.
EXEC SQL.
TRUNCATE TABLE "ZPRINT_LOC"
ENDEXEC.
*------display the data from the internal table
LOOP AT itab into wa1.
WRITE:/ wa1-mandt,wa1-zloc_code,wa1-zloc_desc,wa1-zloc,wa1-zstate.
ENDLOOP.
insert ZPRINT_LOC from table itab. -
How can we give the Data Format (File Type ) in Runtime
Hi all,
How can we give the Data Format (File Type ) in Runtime for the following method,
cl_gui_frontend_services=>gui_download.
Thanks in advance
SriThere is a filetype parameter which you can set
CALL METHOD cl_gui_frontend_services=>gui_download
EXPORTING
* BIN_FILESIZE =
filename =
* FILETYPE = 'ASC'
* APPEND = SPACE
* WRITE_FIELD_SEPARATOR = SPACE
* HEADER = '00'
* TRUNC_TRAILING_BLANKS = SPACE
* WRITE_LF = 'X'
* COL_SELECT = SPACE
* COL_SELECT_MASK = SPACE
* DAT_MODE = SPACE
* CONFIRM_OVERWRITE = SPACE
* NO_AUTH_CHECK = SPACE
* CODEPAGE = SPACE
* IGNORE_CERR = ABAP_TRUE
* REPLACEMENT = '#'
* WRITE_BOM = SPACE
* TRUNC_TRAILING_BLANKS_EOL = 'X'
* IMPORTING
* FILELENGTH =
changing
data_tab =
* EXCEPTIONS
* FILE_WRITE_ERROR = 1
* NO_BATCH = 2
* GUI_REFUSE_FILETRANSFER = 3
* INVALID_TYPE = 4
* NO_AUTHORITY = 5
* UNKNOWN_ERROR = 6
* HEADER_NOT_ALLOWED = 7
* SEPARATOR_NOT_ALLOWED = 8
* FILESIZE_NOT_ALLOWED = 9
* HEADER_TOO_LONG = 10
* DP_ERROR_CREATE = 11
* DP_ERROR_SEND = 12
* DP_ERROR_WRITE = 13
* UNKNOWN_DP_ERROR = 14
* ACCESS_DENIED = 15
* DP_OUT_OF_MEMORY = 16
* DISK_FULL = 17
* DP_TIMEOUT = 18
* FILE_NOT_FOUND = 19
* DATAPROVIDER_EXCEPTION = 20
* CONTROL_FLUSH_ERROR = 21
* NOT_SUPPORTED_BY_GUI = 22
* ERROR_NO_GUI = 23
* others = 24 -
Can someone please let me know the reason(s) why appending data to an existing file only works with TEXT file and It does not work for MS word decoment or MS Excel file ?
Is there another way ( Methods ) to append to these type of files than RandomAccessFile or ByteBuffer methods
Thanks in advance
IBFor example, maybe the Word format looks like this:
First 256 bytes: a directory listing
Bytes 257 to N (as defined by directory): textual data
Bytes N to M (again defined by directory): local dictionaries or other support data
Bytes M to end: undo information, in a stack structure.
And each of those subsections have their own format with their own intricacies.
If that were the format, adding more data to the end wouldn't do anything other than corrupt the file.
I don't know if it's the actual format...I'm sure it's not...but I'll bet there are some similarities and it's closer to that than to a plain text file. -
Attempting to write data to file, but getting error 200279
I am having trouble when writing data to a file. About 10 seconds into the saving process, I get the error 200279. I have done some research on the topic, but am unable to corect my code. I believe I do not want to increase the buffer size, but would rather, I assume, read the data more frequently. The way I save my file is, before running the VI, I assign a location and name of the file (e.g. data.csv). The date and time is appended to the end of the actual file when the I begin to save the data (e.g. data_07-26-13_122615.csv). If the file does not exist, it creates a new file, then appends data to that file after every loop iteration. The reason I did it this way was so I do not have to worry about running out of memory, but apparently my code is flawed.
I will include a copy of the flawed section of my code. Any help would be greatly appreciated.
Thanks.
Solved!
Go to Solution.
Attachments:
data_acquisition.vi 127 KBYour problem is that writing to disk is slow. It is slow enough that it is causing your DAQ buffer to overflow and cause the error and loss of data. What you need to do is implement a Producer/Consumer. This will put the daq and the logging to disk in seperate loops. This will allow the DAQ to run at the speed it needs to keep up with incoming samples and the writing to disk can run at whatever rate it can. You send the DAQ data to the logging loop using a queue.
You might also want to think about changing how you write to the file. That VI is constantly opening and closing the file, which is a very slow process if you are doing it inside of a loop.
There are only two ways to tell somebody thanks: Kudos and Marked Solutions
Unofficial Forum Rules and Guidelines -
A question in appending data to excel
Hi,
Just a quick question, when I tried to use "write file" component of transactions to append data (eg. 00012345) to .csv file, Excel automatically converted it from "00012345" to "12345" . Anyone can tell me how to modify the expression in the Link Editor to resolve this problem?
Thanks..Be sure that the value is in quotation marks, as in "000012345", in the CSV file. This might give Excel the "hint" that it is to be treated as a string, not a number.
-
Problem with Date - Text File Source and Oracle Target
Hi All,
I have a source data (text file) with date column in the format of 'MM/DD/YYYY'. My target is oracle. I am using the LKM FILE TO SQL and IKM SQL Control Append. When i execute this interface, i am getting an error as
7000 : null : com.sunopsis.jdbc.driver.file.b.i
com.sunopsis.jdbc.driver.file.b.i
at com.sunopsis.jdbc.driver.file.b.f.getColumnClassName(f.java)
at the Load Data step.
How to load date columns from text file to oracle tables? Please help me in resolving this...
Thanks in Advance,
Ram Mohan TThe worst solution is to define for your text file the date as a string and then to rebuild your date type in Oracle.
something like
convert(Substr(myfield,4,2)||Substr(myfield,1,2)||Substr(myfield,7,4) ,'MMDDYYYY')
this is maybe the worst solution but it should work.
Regards
Brice
Maybe you are looking for
-
My wife and I each have an itunes account. We just got a new imac, and want to put all of our media on it. Can we share songs and media from two diffrent accounts on the imac, our iphones, and the ipad2?
-
Hi, I want to create a thread safe singleton class. But dont want to use the synchronized method or block. One way i could think of was initializing the object in static block. This way the instance will be created only once. But what if instance bec
-
Help on interface to store CAD/CAM drawings into oracle database using form
i am using forms 6i and oracle 8i. i am able to store .jpg and other picture files into data base.now my problem is how show and store the CAD/CAM drawings using forms. can any one help me please. is higher version is providing any new facility for t
-
Hi, i have monitored that the SQL Developer slows down if you have a lot of connections in your connection tree (i have 100-200 connections in my tree); if i start an clean installation without any connection it starts within 30sek But with my connec
-
Can't Access USB disk attached to Time Machine
When I try to access a disk attached to my Time machine USB port, I get the message :The operation can't be completed because the original item for "Untitled" can't be found. I can access the disk normally in a direct attached mode USB port on my M