How can I read a image file through URI?
I have a image file store in my computer's Image directory on drive E. I name the pathname as:
file:////MyComputerName/e:/image/
the image filename is MyImage.JPG
so I create a ImageIcon use:
String uri = "file:///MyComputerName/e:/image/";
String imagefilename = "MyImage.JPG";
ImageIcon ii = new ImageIcon( uri+imagefilename);
Image myimage = ii.getImage();but I can not get the image.
Does anyone know what's wrong?
Thank you
Read the documentation for ImageIcon(String path) -- the String is a file path,
not a URL. If you want to pass a URL to ImageIcon, use ImageIcon(URL url).
So, either of the following works:
URL url = new URL("file:///e:/image/MyImage.JPG");
ImageIcon imageIcon1 = new ImageIcon(url);
String path = "e:/image/MyImage.JPG";
ImageIcon imageIcon2 = new ImageIcon(path);In case you even need it, to convert a file into a URL, you can write:
URL url = file.toURI().toURL();And finally, you may want to check out BufferedImage and ImageIO.
You can read in a BufferedImage in one line:
BufferedImage image = ImageIO.read(file_or_url_etc);and a BufferedImage offers may advantages over a plain old image.
Similar Messages
-
How can I upload a (image) file through an applet ?
How can I upload a (image) file through an applet ?
have a look at http://www.haller-systemservice.net/jupload/
i'm using Apache Jakarta HTTPClient to create a new HTTP connection to the webserver and sending a new POST request, which holds the image file. (So it's RFC1867 conform)
there is also an open source implementation of such an applet on sourceforge. it's also called JUpload, but i think it's not maintained any more. -
Can we read a ZIP file through ESB file adapter?
Hi,
Is it possible to read a ZIP file from a specified locaiton either through a FTP adapter or file adapter as a opaque element and place it in another specified locaiton?
So far the available options are to read a txt, csv, fixed length or cobol file.
I tried to create a ESB reading ZIP file and place it in another locaiton. but it was not reading the ZIP file.
Is it first possible for the ESB to read the ZIP file? if so then is there any specific configuratuion that we have to do for it to work?how can we read a MSWORD file through java?You can read it like any other file using FileInputStream
and similar.
Howvere, if you want do do something with it, like display
it, you have a problem. AFAIK Microsoft do not release
information about their document formats, and i have not
seen a .doc viewer for java. -
How can i upload a image file to server by using jsp or servlet.
Hi,
I m gurumoorthy. how can i upload a image file to server by using jsp or servlet without using third party API. pls anyone send me atleast outline of the source code.
Pls send me anyone.
Regards,
Gurumoorthy.I'm not an applet programmer so I can't give you much advice there.
If you want to stream the file from the server before it's entirely uploaded, then I don't believe you can treat it like a normal file. If you're just wanting to throw it up there and then listen to it, then you can treat it like a normal file.
But again, I'm not entirely certain. You might be able to stream the start of the file from the server while you're still uploading the end of it, but it probably depends on what method you're using to do the transfer. -
How to get and display image file through servlet
If I've got a jpg file on the server..
How can I use servlet to return that image via the following calling method
/displayfile?filename=image.jpg
the image.jpg in the server will return
I know that I need to set the content type to image/jpeg
after that, how can I return the image file to browser?- Get the "file" Parameter from the URL QueryString
- check if the File specified exists on your filesystem
- read in the jpg from the file (best would be binary)
- set the right Mime Type (as you already wrote)
- write the filecontent to the ServletOutput as you would do with any other content
- that's it. -
How can one read a Excel File and Upload into Table using Pl/SQL Code.
How can one read a Excel File and Upload into Table using Pl/SQL Code.
1. Excel File is on My PC.
2. And I want to write a Stored Procedure or Package to do that.
3. DataBase is on Other Server. Client-Server Environment.
4. I am Using Toad or PlSql developer tool.If you would like to create a package/procedure in order to solve this problem consider using the UTL_FILE in built package, here are a few steps to get you going:
1. Get your DBA to create directory object in oracle using the following command:
create directory TEST_DIR as ‘directory_path’;
Note: This directory is on the server.
2. Grant read,write on directory directory_object_name to username;
You can find out the directory_object_name value from dba_directories view if you are using the system user account.
3. Logon as the user as mentioned above.
Sample code read plain text file code, you can modify this code to suit your need (i.e. read a csv file)
function getData(p_filename in varchar2,
p_filepath in varchar2
) RETURN VARCHAR2 is
input_file utl_file.file_type;
--declare a buffer to read text data
input_buffer varchar2(4000);
begin
--using the UTL_FILE in built package
input_file := utl_file.fopen(p_filepath, p_filename, 'R');
utl_file.get_line(input_file, input_buffer);
--debug
--dbms_output.put_line(input_buffer);
utl_file.fclose(input_file);
--return data
return input_buffer;
end;
Hope this helps. -
How can I read the bootstrap files of any HDS Live stream and extract the fragment-URLs and fragment-numbers in plain text?
Could it be that it is some kind of compressed format in the bootstrap? Can I uncompress it wirh f4fpackager.exe? Could not find any download for f4fpackager.exe. I would prefere less code to do so. Is there something in Java of JavaScript, that can extract the fragment-numbers?
Thank you!Doesn't sound too hard to me. Your class User (the convention says to capitalize class names) will have an ArrayList or Vector in it to represent the queue, and a method to store a Packet object into the List. An array or ArrayList or Vector will hold the 10 user objects. You will find the right user object from packet.user_id and call the method.
Please try to write some code yourself. You won't learn anything from having someone else write it for you. Look at sample code using ArrayList and Vector, there's plenty out there. Post in the forum again if your code turns out not to behave. -
How can i read local excel file into internal table in webdynpro for abap a
Could someone tell me how How can i read local excel file into an internal table in webdynpro for abap application.
thank u for your replyDeep,
File manuplations...............................
1. At the presentation level:
->GUI_UPLOAD
->GUI_DOWNLOAD
->CL_GUI_FRONTEND
2. At the application server level:
->OPEN DATASET : open a file in the application server for reading or writing.
->READ DATASET : used to read from a file on the application server that has been opened for reading
-> TRANSFER DATASET : writing data to a file.
-> CLOSE DATASET : closes the file
-> DELETE DATASET : delete file
If file is on the local PC,use the function module GUI_UPLOAD to upload it into an internal table by passing the given parameters......
call function 'GUI_UPLOAD'
exporting
filename = p_file
filetype = 'ASC'
has_field_separator = '#'
tables
data_tab = t_data
p_file : excel file path.
t_data : internal table
<b>reward points if useful.</b>
regards,
Vinod Samuel. -
How can i display a image file which is placed in the applications server
Hi all,
Can any one help me how can I display a image file which is present in the application server.
With regards,
M.Ramana Murthyhi,
*& Form TOP_OF_PAGE
* text
FORM F_TOP_OF_PAGE.
CALL FUNCTION 'REUSE_ALV_COMMENTARY_WRITE'
EXPORTING
IT_LIST_COMMENTARY = IT_LISTHEADER
i_logo = Logo name
* I_END_OF_LIST_GRID =
ENDFORM. "TOP_OF_PAGE
rgds
Anver -
How can I read the EXCEL file while Program is running in background.
Hi all Expert,
How can I read the EXCEL file while Program is running in background.
Thanksyou need to place ur excel file on application server and follow this thread: Reading an Excel file from the application server?
loots of information if you can search forum.. thanks -
How can I read the image from database into form
hi everyone
if I have table like this
create table test
(id number(10),
pic long raw);
in this table record
in form If I have block non database
how can i read the image into non database item
I try with this code but no good
select pic into :photo from test where id=5;
photo its non database item kind image
how can i invoke image into item
thanks aloooooootHello,
You can't select image with select query. You need to create another database block from test table which has item binds with database pic column. Now in where condition in test block's property you have to write id=5. Change test block's properties UPDATE ALLOWED, INSERT ALLOWED, DELETE ALLOWED to NO. Only Query allowed property set to YES.
Now in your particular trigger write the code
GO_BLOCK('test');
Execute_Query;
please mark if it help you or correct
Regards,
Danish -
How can I read from a file line by line?
Hi!
Could someone post some code or explain how can I read from a file, and want I to read a line each time. How can I go to line number N?
Thankshi,
u can try this:
try {
// open text file
BufferedReader in = new BufferedReader(new FileReader(fileName));
String line=in.readLine();
while((line=in.readLine()) != null) {
System.out.println(line);
}The go to line number N i m not so sure.
Cheers
Jerry -
How can I read a Excel file?
How can I read an Excel file and compare if the cells type are numeric or not??
i hope you can can give me a hand..
thanksIf you want to use plsql try utl_file supplied package to read the excel file -> http://psoug.org/reference/utl_file.html
And you can use a function like this to understand if the column is number or not ;
CREATE OR REPLACE FUNCTION is_number (
char_in VARCHAR2)
RETURN BOOLEAN
IS
n NUMBER;
BEGIN
n := TO_NUMBER(char_in);
RETURN TRUE;
EXCEPTION
WHEN OTHERS THEN
RETURN FALSE;
END is_number;
DECLARE
x BOOLEAN;
BEGIN
IF is_number('ABC') THEN
dbms_output.put_line('TRUE');
ELSE
dbms_output.put_line('FALSE');
END IF;
END;
/ -
How can i read a image from a oracle DB?
How can i read a image from a oracle DB?
Because in the DB a have a field that is a picture that i would like to show in a jpanel.....but this field is in oracle DB only has strange caracters ..... so Do i have to read this field like a input stream?....
Could some body help me please?
Thanks...
MaryWell I suppose the picture is stored in a blob. If that is so this is some code I have used to load a picture to a panel. Hope you find it usefull.
PreparedStatement retreive = db.createPreparedStatement("select bl from test where ln = ?");
Blob bl;
try{
retreive.setBigDecimal(1, new BigDecimal(jTFln.getText()));
ResultSet rs = retreive.executeQuery();
if (!rs.next())
System.out.println("Empty Result Set");
bl = rs.getBlob("bl");
if (bl == null) {
System.out.println("Null Blob");
return;
InputStream is = bl.getBinaryStream();
int imageLength = (int) bl.length();
System.out.println(imageLength);
System.out.println(bl.length());
byte[] imageData = new byte [imageLength];
is.read(imageData, 0, imageLength);
image1 = new ImageIcon(imageData);
photo = new JPanel() {
public void paint(Graphics g){
g.setColor(Color.lightGray);
g.drawImage(image1.getImage(), 0, 0, this);
} catch (BadLocationException ble){
ble.printStackTrace();
} catch (SQLException sqle){
sqle.printStackTrace();
} catch (IOException ioe){
ioe.printStackTrace();
} -
Signed Applet can't read an image file??
Hi my dear java folks,
I've written a simple applet and self-signed it in order to have access
to local machine's files.
The applet as you see needs to read an image file (arrow.gif).
The applet is:
import.....
public class MyApplet extends JApplet{
JButton button1=new JButton("Save");
JButton button2=new JButton(new ImageIcon("arrow.gif"));
public void init(){
button1.setBounds(10,70,80,20);
button2.setBounds(10,100,80,20);
getContentPane().setLayout(null);
getContentPane().add(button1);
getContentPane().add(button2);
The java.policy file is:
keystore ".//myworkingstore.store";
grant codeBase "http://fin2000/htdocs/MyApplet.class" {
permission java.io.FilePermission "<<ALL FILES>>","read";
permission java.io.AllPermission;
grant codeBase "." signedBy "MyName" {
permission java.io.FilePermission "${user.home}/*.*","read,write";
permission java.io.FilePermission "<<ALL FILES>>","read";
permission java.io.AllPermission;
The java.security file is on the server
(on my server I have Oracle8.1/Apache installed):
policy.url.1=file:d:/oracle/ora81/apache/apache/htdocs/java.policy;
My problem is when I run my applet through a html file
"http://myServerName/test.html" in my browser, the applet
runs correctly except it's button2 (the iconized button), the
button comes without it's ImageIcon on it.
I receive no errors, no messages and no signs of error
I am completely confused!
Need Urgent Help
Thank you , JamanirHi,
this has nothing to do with a security problem.
Change you code as follow:
JButton button2 = new JButton(new ImageIcon(getClass().getResource("arrow.gif")) ;Pack arrow.gif in the same directory/package as MyApplet.class in the jar file and It should solve your problem...
The problem is that when you write new ImageIcon("arrow.gif"), it works locally as a standalone application, because "arrow.gif" is mapped to the current directory where you application is started from. This has no meaning when you works online with an applet. That's the reason why your graphic was not found.
getClass().getResource("arrow.gif") returns an URL pointing to a file "arrow.gif" located at the same location as the class. This always works either locally or online, other packed in a Jar file, or unpacked.
Yannick
Maybe you are looking for
-
every time i plug my ipod touch 5th gen into itunes it tells me that the itunes sync session has been timed out what dose this mean? and what can i do to fix this i need help guys and this only happen when i click sync to put music on
-
i upgraded iTunes to 10.5.1 and all my music disappeared after syncing. How do I get it back?
-
Like I said. . . I recently migrated from an old MacBook to a new MacBook Air. I decided that since I have many tens of thousands of photos, I would keep them all on an external hard drive in the dedicated "iPhoto Library" (which I was very careful t
-
My brushes look pixelated. What's going on?
I started Ps today and when I used the default soft round brush, it looked like this. The other brushes also look similar, like pixelated.
-
I exported 2267 images from Aperture to an external drive in original format with original filenames. I tried to import them into LR3.6 and it will only recognize about 1800 of them. Files consist of RAW files and Jpg and maybe a few Tiffs. RAW fil