How to write to a file
Hi
I need help in writing to a file
i have given the sample code
f="mmapi_pic_0000";//file present in root device
ByteArrayOutputStream baos = null;
FileConnection from = (FileConnection)
Connector.open(
"file://" + snpCtrl.getDirectory()+"/"+f+".png");
InputStream fis = from.openInputStream();
int fileSize = (int)from.fileSize();
byte [] buff = new byte[fileSize];
int length = fis.read(buff, 0, fileSize);
baos = new ByteArrayOutputStream(1024);
baos.write(buff, 0, buff.length);
System.out.println(buff.length+f);
imageData = baos.toByteArray();
fis.close();
baos.close();
from.close();
//creating the image from the bytes
Image im = Image.createImage(imageData, 0, imageData.length);
//calling the function
createThumbnail(im);
//the function createThumbnail
private Image createThumbnail(Image image) {
int sourceWidth = image.getWidth();
int sourceHeight = image.getHeight();
int thumbWidth = 64;
int thumbHeight = -1;
if (thumbHeight == -1)
thumbHeight = thumbWidth * sourceHeight / sourceWidth;
Image thumb = Image.createImage(thumbWidth, thumbHeight);
Graphics g = thumb.getGraphics();
for (int y = 0; y < thumbHeight; y++) {
for (int x = 0; x < thumbWidth; x++) {
g.setClip(x, y, 1, 1);
int dx = x * sourceWidth / thumbWidth;
int dy = y * sourceHeight / thumbHeight;
g.drawImage(image, x - dx, y - dy,
Graphics.LEFT | Graphics.TOP);
Image immutableThumb = Image.createImage(thumb);
return immutableThumb;
after this the image that is changed should be saved in the root file system by the same name(mmapi_pic_0000).how to do this?
please help me.
URL url = new URL("http://hostname/filename.txt);
BufferedWriter out = new BufferedWriter(new OutputStreamWriter(url.openStream()));
out.write("data");
Similar Messages
-
HELP!!!!!! - How to write into a file?
How to write into a file?
I want to make a script that will connect(not enter) to my website[for example, www.vasa.com] every time i connect to the internet.
Now i have 3 problems:
1. i dont know how to write into a file
2. i dont know how to make it connect to my 'server' without entering the website
3. i dont know what file to write it to
so if someone can help me, please do.Well, how about RTFM?? In this case that can be found here:
http://developer.java.sun.com/developer/onlineTraining/
BTW - these things have been asked azillion times, search the forum. -
How to write a CSV file in OSB
Hi All,
can any one tell me How to write a CSV file in OSB?
Thanks.Hey, I couldnot find any xsl usage inside pipeline pair in the links given by you. Do you have any links that gives a sample example.I could not find any links with examples. I will send you a simple config jar demonstrating the use of XSLT resources/transformations.
secondly should MFL doc replicate the name(s)of the nodes of the source xsd:I'm not sure If I understood your question.Can you please explain?
Ex: My database schema looks like:
<?xml version = '1.0' encoding = 'UTF-8'?>
<xs:schema targetNamespace="http://xmlns.oracle.com/pcbpel/adapter/db/top/AssetsPoll" xmlns="http://xmlns.oracle.com/pcbpel/adapter/db/top/AssetsPoll" elementFormDefault="qualified" attributeFormDefault="qualified" xmlns:xs="http://www.w3.org/2001/XMLSchema">
<xs:element name="CountriesCollection" type="CountriesCollection"/>
<xs:complexType name="CountriesCollection">
<xs:sequence>
<xs:element name="Countries" type="Countries" minOccurs="0" maxOccurs="unbounded"/>
</xs:sequence>
</xs:complexType>
<xs:complexType name="Countries">
<xs:sequence>
<xs:element name="countryId">
<xs:simpleType>
<xs:restriction base="xs:string">
<xs:maxLength value="2"/>
</xs:restriction>
</xs:simpleType>
</xs:element>
<xs:element name="countryName" minOccurs="0" nillable="true">
<xs:simpleType>
<xs:restriction base="xs:string">
<xs:maxLength value="40"/>
</xs:restriction>
</xs:simpleType>
</xs:element>
<xs:element name="regionId" type="xs:decimal" minOccurs="0" nillable="true"/>
</xs:sequence>
</xs:complexType>
</xs:schema>
and the corresponding MFL that I have created gives this output
<?xml version="1.0" encoding="windows-1252"?>
<countriesCollection1>
<Countries>
<counrtyId>counrtyId</counrtyId>
<country_name>country_name</country_name>
<regionId>regionId</regionId>
</Countries>
<Countries>
<counrtyId>counrtyId</counrtyId>
<country_name>country_name</country_name>
<regionId>regionId</regionId>
</Countries>
</countriesCollection1>
Why I am asking this beacuse there is an error that i am getting:
Jun 19, 2009 5:50:50 PM IST> <Error> <JCATransport> <BEA-381951> <JCA inbound r
quest only invocation failed, exception: java.security.PrivilegedActionExceptio
: com.bea.wli.sb.transports.TransportException: Binary to XML mfl transformatio
failed for the MFL Resource Database-Jms-File/Database-File/MFLSample : null
ava.security.PrivilegedActionException: com.bea.wli.sb.transports.TransportExce
tion: Binary to XML mfl transformation failed for the MFL Resource Database-Jms
File/Database-File/MFLSample : null..................................................
Any help?
Regards
PS -
How to write run.bat files
Can anyone tell me how to write run.bat files to run java classes. Currently my run.bat file has the following two lines,
c:\j2sdk1.4.1_02\bin\javac.exe *.java
c:\j2sdk1.4.1_02\bin\java.exe questionnair
But the class is not executed. Thanks in advance.you'll have to provide more details.
Firstly, which package is the class a part of? and secondly, where on the filesystem is the root of the package?
You might also benifit from placing the c:\j2sdk1.4.1_02\bin\ into the classpath.
On a rainy day, check out the ANT tool, it will take care of all that crapola for you.
newio -
Can any one tell me how to write the properites files and how to acces
can any one tell me how to write the properites files and how to acces thoose files
plz let me no
thanks in advancehttp://www.exampledepot.com/egs/java.util/Props.html
-
How to write won WSDL file for SOAP adapter ?
Hi experts
Can any one expalin me how to write WSDL file for SOAP adapter ?
What and all things i need to know ? i have no idea on this....
I got the business but to WSDL ...i am very new to this
Adv...thanks
RakeshHI,
Please see the below links,
Consuming XI Web Services using Web Dynpro Part II-/people/riyaz.sayyad/blog/2006/05/08/consuming-xi-web-services-using-web-dynpro-150-part-ii
Consuming XI Web Services using Web Dynpro Part I -/people/riyaz.sayyad/blog/2006/05/07/consuming-xi-web-services-using-web-dynpro-150-part-i
https://www.sdn.sap.com/irj/sdn/go/portal/prtroot/docs/library/uuid/0d7349b6-0901-0010-ddbe-ec43178a61ff
/people/sap.user72/blog/2006/01/16/xi-propagation-of-meaningful-error-information-to-soap-client
/people/kevin.liu/blog/2006/04/12/wsdl-11-binding-extension-for-soap-12
Regards
Chilla.. -
How to write 3 AVI files from 3 different cameras connected to 3 PCI 1411's?
I have a multiple camera acquisition vi and a AVI read/write vi, but I want to acquire from 3 cameras and write 3 AVI files simultaneously. The multiple camera vi uses buffers but the AVI read/write vi does not(I think). How can I accomplish my goal?
Your best bet is to use the new IMAQ Vision 7, which was released last Tuesday, I believe. It now has native support for writing compressed AVI movie files. These VIs are used the same way the Write BMP.vi and other file I/O VIs are used in IMAQ Vision 6.1.
Writing 3 files simulateously should be fairly straightforward. If you can get it to work with one camera (img0), then just copy and past the code two more times for img1 and img2. Also write to three different AVI files. That's all you should have to change! Bandwidth to the harddisk may be another matter all together...
Kyle V -
How to write output to file in flash
hi all experts.
I want to monitor a specific link. Lets say when it goes down, i want to write the following to a file in flash called link_mon.txt
link down <show clock output>
When it gets back up
link up <show clock output>
I know how to write the applets and use sla tracking for monitoring, i just want to know how to write the output(user defined) to a file in flash ?What you want to do is not possible using applets. You can write CLI output to flash using the redirect command:
action 1.0 cli command "enable"
action 2.0 cli command "show clock | redirect flash:/output.txt"
But you cannot include your own custom text. For that, you will need to use an EEM Tcl policy. Within the Tcl policy, the code to write the output to flash would look like:
if { [catch {cli_open} result] } { error $result $errorInfo}array set cli $resultset fd [open "flash:/output.txt" "a"]set output [cli_exec $cli(fd) "show clock"]puts $fd "link down $output"close $fd -
How to write data to file Java ME cldc 1.1 midp 2.0?
I newly in java me, please help me.
I make project in NetBeans 7.0.1. and use cldc 1.1 midp 2.0.
I want to write data to the file.
How can I do it?
I try to use FileOutputStream. But it don't exists in java.io
NetBeans shows me only this list of classes and interfaces in java.io:
ByteArrayInputStream, ByteArrayOutputStream, DataInput, DataInputStream, DataOutput, DataOutputStream, InputStream, InputStreamReader, OutputStream, OutputStreamWriter, PrintStream, Reader, Writer.
Why it so short?
And how I can write data to file?
Data can be array of bytes (byte[]) or Object it better.You must use JSR 75: FileConnection. Please check the following article "Getting Started with the FileConnection APIs":
http://developers.sun.com/mobility/apis/articles/fileconnection/
Be sure to use FileSystemRegistry.listRoots().
And welcome to Java ME development. :) -
How to write in a file without erase it each time I want to write inside
Hi
My problem is to write in a unique file without erasing what I have written inside before.
Because I use an Applet and I write some information in afile each time the user push a button but I want to keep all the information, beacause in my case I only have the last information i.e. the last time the user push the button.
My code is:
Below it is the code where I write in the file:
writer2 = new BufferWriter("chemin.txt");
methode = uneMethode;
eps = unEps;
n = unN;
solExacte=uneSolExacte;
y=z;
Date time =new Date();
Vector valeur = new Vector();
valeur.add(new Double(eps));
valeur.add(new Integer(n));
valeur.add(new Integer(solExacte));
valeur.add(new Integer(methode));
String time_string = time.toString();
valeur.add(new String(time_string));
//writing to variables file
BufferWriter writer = new BufferWriter("variables");
writer.write(valeur);
Now it is the class Bufferwriter:
import java.io.BufferedWriter;
import java.io.FileWriter;
import java.io.IOException;
import java.util.Vector;
import java.io.File;
public class BufferWriter {
private String fileName;
BufferedWriter w;
public BufferWriter(String name) throws IOException {
fileName=name;
w=new BufferedWriter(new FileWriter(new File(fileName)));
public void write(Vector v) throws IOException {
String string;
for (int i=0; i<5; i++) {
string=((v.get(i)).toString());
w.write(string,0, string.length());
w.newLine();
w.flush();
public void close() throws IOException{
close();}try
w=new BufferedWriter(new FileWriter(fileName, true));
The Constructor you want is ..
FileWriter
public FileWriter(String fileName,
boolean append)
throws IOException -
How to write to csv file - Whats wrong with this???
Hi ALL,
I created a view that does all sorts of calculations, now I need to write the output in csv file. How do I do this thru a procedure? Sorry I've never had to create a csv file before and this is my first time.
Thanks!
Edited by: user5737516 on Nov 18, 2009 9:47 AMWhat is wrong with this?? Am I supposed to do something else before I could run this?
CREATE OR REPLACE DIRECTORY PAYROLL as 'c:\';
Directory created.
grant read, write on directory PAYROLL to my_user;
Grant succeeded.
CREATE OR REPLACE PROCEDURE baninst1.PAY_CSV(p_year NUMBER, p_qtr NUMBER) AS
CURSOR c_data IS
SELECT pay_period,
pay_group,
p_qtr,
check_date,
SUM(soc_sec_gross) as SOC_SEC_GROSS,
SUM(medicare_gross) as MEDICARE_GROSS,
SUM(TOTAL_DEDUCTIONS) as Total_Deductions,
SUM(NET_PAY) as Net_Pay
FROM baninst1.pzvdedn
WHERE pay_year = p_year
AND p_qtr = p_qtr
GROUP BY pay_period, pay_group, check_date, pay_qtr
ORDER BY pay_period, pay_group, check_date, pay_qtr;
v_file UTL_FILE.FILE_TYPE;
BEGIN
v_file := UTL_FILE.FOPEN('PAYROLL',
'pay_csv.csv',
'w',
max_linesize => 32767);
FOR cur_rec IN c_data LOOP
UTL_FILE.PUT_LINE(v_file,
cur_rec.pay_period || ',' ||
cur_rec.pay_group || ',' ||
cur_rec.check_date || ',' ||
cur_rec.soc_sec_gross || ',' ||
cur_rec.medicare_gross || ',' ||
cur_rec.total_deductions || ',' ||
cur_rec.net_pay);
END LOOP;
UTL_FILE.FCLOSE(v_file);
EXCEPTION
WHEN OTHERS THEN
UTL_FILE.FCLOSE(v_file);
END;
Procedure created.
SQL> exec baninst1.PAY_CSV(2009,1);
BEGIN baninst1.PAY_CSV(2009,1); END;
ERROR at line 1:
ORA-20003: File could not be opened or operated on as requested.
ORA-06512: at "BANINST1.PAY_CSV", line 45
ORA-06512: at line 1Edited by: user5737516 on Nov 18, 2009 9:16 AM
Edited by: user5737516 on Nov 18, 2009 9:18 AM
Edited by: user5737516 on Nov 18, 2009 9:20 AM
Edited by: user5737516 on Nov 18, 2009 9:35 AM -
How to write to a file with \n (new line)???
Hi there,
I have the following method that reads a file's content and convert it into a string:
public static String getFileContent(String fileName) throws IOException
File file = new File(fileName);
FileInputStream fileInputStream = new FileInputStream(file);
BufferedReader bufferedReader = new BufferedReader(new InputStreamReader(fileInputStream));
StringBuffer stringBuffer = new StringBuffer();
String line;
while ( (line=bufferedReader.readLine()) != null )
stringBuffer.append(line+"\n");
return stringBuffer.toString();
}I'm trying to write a method that writes a String to a file WITH THE NEW LINE. All classes I used (DataOutputStream, FileWriter, PrintStream...) do not force a new line (I get everything in one line)
I thought maybe I should change the "\n" in the line
stringBuffer.append(line+"\n"); but...didn't know what.
thanks for any adviseBufferedReader readLine remove the newline sequence. But you're putting \n back which should do what you appear to want.
However newline sequence isn't always just \n, on unix systems it's \n, on windows its \r\n (reads "carriage-return, linefeed"). Sytem.getProperty("line.separator"); will get you the appropriate end of line string. -
How to write the java file and number line where execution point is?
I'd like to log errors encountered by a home made java server to a file.
To be effective, here is how I'd like to build the string to log, roughly :
String locError = "ERROR: in "+ filename +" => "+ methodname +", line "+ linenumber +"\n"; Is there a way in java to get such informations? Via reflection?
I doubt so but I'd like to make sure.
Thanksbestam wrote:
I'd like to log errors encountered by a home made java server to a file.
To be effective, here is how I'd like to build the string to log, roughly :
String locError = "ERROR: in "+ filename +" => "+ methodname +", line "+ linenumber +"\n"; Is there a way in java to get such informations? Via reflection?
I doubt so but I'd like to make sure.
ThanksNot quite sure what you mean here. Are you trying to print out the contents of an actual Java error? If so, Throwable.getStackTrace() or Throwable.printStackTrace() are probably what you want.
Winston -
How to write into a file from an applet?
Dear,
I made an applet and I want to create a file in a machine. I tried many way but it not work.
Here is the code:
URL url = "http://hostname/filename.txt;
URLConnection con = url.openConnection();
OutputStream out = con.getOutputStream();
out.write(data);
out.flush();
out.close();
Please help me resolve it.
Thanks.
KhaiURL url = new URL("http://hostname/filename.txt);
BufferedWriter out = new BufferedWriter(new OutputStreamWriter(url.openStream()));
out.write("data"); -
HOW TO WRITE ,SAVE A FILE IN BLOB COLUMN
Hi,
I have to write a simple utl file and store it in a column of blob data tye..i hav written a piece of code..it shows invalid path as error..please kindly help me
create or replace
procedure simp_file as
fhandler utl_file.file_type;
f_dir VARCHAR2(100);
f_file VARCHAR2(100);
BEGIN
f_dir := 'C:/utl/';
f_file := 'Kings.txt';
BEGIN
fhandler := utl_file.fopen(f_dir,f_file,'a');
EXCEPTION
WHEN utl_file.invalid_path THEN
f_dir := 'C:/utl/';
fhandler := utl_file.fopen(f_dir,f_file,'a');
END;
utl_file.new_line(fhandler,1);
utl_file.putf(fhandler,'hi');
utl_file.fclose(fhandler);
EXCEPTION
WHEN UTL_FILE.INVALID_PATH THEN
IF (utl_file.is_open(fhandler)) THEN
utl_file.fclose(fhandler);
END IF;
raise_application_error(-20101, 'Invalid path');
END simp_file;May be..
SQL> CREATE TABLE test_blob (id INTEGER,blob_col BLOB);
Table created.
SQL> DECLARE
2 file_handle UTL_FILE.file_type;
3 v_fname VARCHAR2(20) := 'mytest.txt';
4 buffer VARCHAR2(32767);
5 BEGIN
6 file_handle := UTL_FILE.fopen('TEST_DIR', v_fname, 'W');
7 buffer := 'This is first line';
8 UTL_FILE.put_line(file_handle, buffer, TRUE);
9 buffer := 'This is second line';
10 UTL_FILE.put_line(file_handle, buffer, TRUE);
11 buffer := 'This is third line';
12 UTL_FILE.put_line(file_handle, buffer, TRUE);
13 UTL_FILE.fclose(file_handle);
14 END;
15 /
PL/SQL procedure successfully completed.
SQL> DECLARE
2 v_src_loc BFILE := BFILENAME('TEST_DIR', 'mytest.txt');
3 v_amount INTEGER;
4 v_b BLOB;
5 BEGIN
6 DBMS_LOB.OPEN(v_src_loc, DBMS_LOB.LOB_READONLY);
7 v_amount := DBMS_LOB.GETLENGTH(v_src_loc);
8 INSERT INTO test_blob
9 VALUES
10 (1, EMPTY_BLOB())
11 RETURNING blob_col INTO v_b;
12 DBMS_LOB.LOADFROMFILE(v_b, v_src_loc, v_amount);
13 DBMS_LOB.CLOSE(v_src_loc);
14 END;
15 /
PL/SQL procedure successfully completed.
SQL> commit;
Commit complete.Then display
SQL> DECLARE
2 v_lob_loc BLOB;
3 CURSOR cur IS
4 SELECT id, blob_col FROM test_blob;
5 v_rec test_blob%ROWTYPE;
6 BEGIN
7 OPEN cur;
8 LOOP
9 FETCH cur
10 INTO v_rec;
11 v_lob_loc := v_rec.blob_col;
12 DBMS_OUTPUT.PUT_LINE('The length is: ' ||
13 DBMS_LOB.GETLENGTH(v_lob_loc));
14 DBMS_OUTPUT.PUT_LINE('The ID is: ' || v_rec.id);
15 DBMS_OUTPUT.PUT_LINE('The blob is read: ' ||
16 UTL_RAW.CAST_TO_VARCHAR2(DBMS_LOB.SUBSTR(v_lob_loc,
17 200,
18 1)));
19 EXIT WHEN cur%NOTFOUND;
20 END LOOP;
21 CLOSE cur;
22 END;
23 /
The length is: 61
The ID is: 1
The blob is read: This is first line
This is second line
This is third line
The length is: 61
The ID is: 1
The blob is read: This is first line
This is second line
This is third line
PL/SQL procedure successfully completed.
Maybe you are looking for
-
Open Item Management for Check Issue / Check Deposit Accounts??
Dear Members, Can we define Check Issue and Check Deposit Accounts as Open Item Management Accounts?? Pls Suggest me. Thank U.
-
My podcast collection has become unmanageable and Apple just keeps mum? no Hot News RSS with an APOLOGY, no keep informed about progress, plan of remedial action, nothing? All I have been told from the Support side is that they'll be fixing mobile ga
-
My Computer Crashed Last night and now itunes is gone what do i do?
Hi I have Windows XP on a HP Pavillion. I have itunes well had it until my computer crashed. Then all my music is gone. I had 30GB of music loaded and $5000 of music purchased from itunes. How do I get that back on my PC? Did I just lose $5000. All t
-
I subscribe to blogs via RSS (whatever that means) and new blog posts show up in my bookmark menu ....... they show up with a grey unassuming icon at the beginning of the blog post bookmark. Months ago the appearance of the bookmarks would "change" w
-
Dear All, Any one know where can I find the IBM Storage Connect plug-in ? One More Problem : My N3200 SAN auto add into : FibreChannel Volume Group but when I add more LUN to the Server, I can't refresh the storge and display following error OVMRU_00