Implementing a directory listener in java...!
Hi guys..!
I wrote a program that creates an Xml file when the program terminates. I want to write some kind of Listener that will listen the directory where the file is created. So, what I want is....as soon as the file is created, I want to be able to get the file from that directory and copy it to a different directory.
In addition, I also want to write a FTP program that will take the created Xml file and send to a different machine.
Does anyone have an idea on how to do that...??? Any help from you guys will be very appreciated...
Thanks...
to copy a file is not difficult, use something like this:
FileChannel sourceChannel = new FileInputStream(in).getChannel();
FileChannel destinationChannel = new FileOutputStream(out).getChannel();
sourceChannel.transferTo(0, sourceChannel.size(), destinationChannel);
sourceChannel.close();
destinationChannel.close();"in" and "out" are File objects.
see api docs of FileChannel for details.
ftp via java: i remember seeing it discussed here recently, ask google or forum search should help ...
Similar Messages
-
Directory monitor in Java, help
Hey everyone,
I'm attempting to write a directory monitor in java but I'm stuck. I'm trying to find something in Java that is like FileSystemWatcher in .NET but I don't think java does. From what I read is that you have to continually poll the directory for changes. What I would like to know is that are there any events and/or signals raised when a changes are made so that one could catch and process them? If not, could someone explain how to simply poll the directory for changes?
Thanks
Barefootbarefootsanders wrote:
This is exactly what I need to do. Now, i already have been working on the last modified time comparison which is relatively simple. What I was stuck on was finding what was different between the two file lists. Would I have to iterate through the entirety of the list and compare each item to find what was different or is there a more efficient way of doing this?The simplest thing to do would be to use Collection's removeAll method to get the difference between the two. This will show you which files have been added (using newList.removeAll(oldList)) and which have been removed (using oldList.removeAll(newList)).
A few notes:
* removeAll modifies the collection on which you call it, so you'll need to make copies.
* File's equals method docs say: Returns true if and only if the argument is not null and is an abstract pathname that denotes the same file or directory as this abstract pathname. Whether or not two abstract pathnames are equal depends upon the underlying system. On UNIX systems, alphabetic case is significant in comparing pathnames; on Microsoft Windows systems it is not.
So you'll need to decide if that's good enough, or if you want to implement your own comparison for files. Also, it's not clear from the above how shortcuts or symbolic links are handled--whether the shortcut and the original are considered equal or not.
* Based on the above, you may get different results with a List vs. a Set, so play around and see which one better suits your needs.
* I think a directory's mod time only changes if you add or remove or rename files, or explicitly change it, as with the touch command in unix. I don't think modifying the contents of an existing directory cause that directory's mod time to be updated. If you want to know when a file has changed, you'll probably have to poll that file's mod time explicitly.
In light of the above, I suggest you start by writing a small program that does nothing but poll a directory every, say, 5 or 10 or 30 seconds and print out whether it's changed or not. Then, while that program is running, do various things like add, delete, rename, rename with same letters but different case, etc. and see if the program gives you the results you want. If not, you'll have to tweak it based on your findings. -
Copying complete directory structure using java.io.File
Is there a solution to problem when you want to copy a complete directory structure using java.io.File class as you can copy when using FTP connection.
Is there a solution to problem when you want to copy
a complete directory structure using java.io.File
class as you can copy when using FTP connection.FTP does not have a command to transfer all the files in a directory. FTP clients implement this by invoking single file transfer for each file in a directory. -
Finding the directory path in java
I need to check if a file exists or not before an action is taken. I used File class to get the handle of a file and and then used exist() function to check if it is there. But this function needs to full path to that file. I need to find a directory path at runtime as the application is deployed in different environment and wouldn't know the directory path in each environment. Could somebody help me on this. Thanks,
fBut this function
needs to full path to that file. I need to find a
directory path at runtime as the application is
deployed in different environment and wouldn't know
the directory path in each environment. Well, that can only you know where this file is on the different platforms. So maybee you can provide it as a user-input, a parameter to the program or be set in a settings-file which the program reads.
If you want the full path to the current directory where the java program runs, this works:
File f=...;
String absPath=f.getAbsolutePath();
File absPathFile=new File(absPath);Gil -
How to use directory alias in Java stored procedure ?
hi everyone !
I want use Directory alias in Java strored procedure
I 'hv created dir alias as
Create Directory BFILE_DIR AS 'C:\MyImages'
my java statements -
myfile="C:\MyImages\myPH01.jpg"
File binaryFile = new File(myFile);
instead of giving absolute path I want give directory alias BFILE_DIR
myfile= BFILE_DIR + "myPH01.jpg"
File binaryFile = new File(myFile);
can anyone pl suugest how should I write this in Java procedure
thanks
SPDhi everyone !
I want use Directory alias in Java strored procedure
I 'hv created dir alias as
Create Directory BFILE_DIR AS 'C:\MyImages'
my java statements -
myfile="C:\MyImages\myPH01.jpg"
File binaryFile = new File(myFile);
instead of giving absolute path I want give directory alias BFILE_DIR
myfile= BFILE_DIR + "myPH01.jpg"
File binaryFile = new File(myFile);
can anyone pl suugest how should I write this in Java procedure
thanks
SPD -
Implement a greedy search in java
Implement a greedy serch in java for the map of romania .goal state is bucharest.
1.not to visit the same city twice
2.give the search trees
3.try 3 initial statesNo. Do it yourself. This is a help forum, not a "here's my requirements do it for me" forum.
-
How to implement a note on a Java AS(i.e.Enterprise portal)
Hello
How to implement a note on a Java AS(i.e.Enterprise portal)
Thx in advanceHi,
Could you please let us know what kind of note you want to implement on EP ?
Thanks
Sunny -
Implementing n-tier Architecture using java
Hi !!
I wish to know how I can proceed to implement n-tier application using java
or how to implement n-tier application with JBuilder.
Thanks!Easypublic class nTier {
public static void main(String[] args) {
int n =5;
for (int i=0; i<n; i++) {
System.out.println(i + " tier");
}Ted. -
Using Directory alias in Java stored procedure
hi !!
I want use Directory alias in Java strored procedure
I 'hv created dir alias as
Create Directory BFILE_DIR AS 'C:\MyImages'
my java statements -
myfile="C:\MyImages\myPH01.jpg"
File binaryFile = new File(myFile);
instead of giving absolute path I want give directory alias BFILE_DIR
myfile= BFILE_DIR + "myPH01.jpg"
can anyone pl suugest how should I write this in Java procedure
thanks
SPDHi there i am currently trying to develope a java
stored procedure and place it in oracle and will try
to use that procedure to send a message to a server
but then it doesnt seems to work. is it possible?And what do you do with exceptions in your java proc?
I haven't ever done it myself, but I would be very surprised if it wasn't possible. I also wouldn't be surprised to find out that you have to configure various things to allow it in Oracle itself. -
Add a posixaccount user in posixgroup in sun directory server using java
Hi
Anybody now how to add posixaccount user in posixgroup in sun directory server using java code.
I am able to add normal directory server user in ldap group in java.
But i am getting any luck to add posixaccount user in posixgroup.
I know we can set uid value in memberuid attribute but how to add through java program.
Anybody can paste code for that.
Thanks.To CRabel,
My company have restriction on using the open sources product/code, but i will take a look on netscape ldap sdk as a reference~
To raghu1978 ,
i find a product call Directory Editor 1 2005Q1, I hope it is useful.
thz all~ -
How to avoid directory listing in java web applications.
how to avoid directory listing in java web applications.
That is on typing the url of the application it should not the directory listing. Welcome tag in web.xml doesnot fully solve the problem, since still the images folder etc is still accessibleI know of two ways.
If you're using tomcat and have access to the conf directory.
Edit your $TOMCAT/conf/web.xml. Find your default servlet properties and change
<servlet>
<servlet-name>default</servlet-name>
<servlet-class>org.apache.catalina.servlets.DefaultServlet</servlet-class>
<init-param>
<param-name>debug</param-name>
<param-value>0</param-value>
</init-param>
<init-param>
<param-name>listings</param-name>
<param-value>true</param-value>
</init-param>
<load-on-startup>1</load-on-startup>
</servlet>to <servlet>
<servlet-name>default</servlet-name>
<servlet-class>org.apache.catalina.servlets.DefaultServlet</servlet-class>
<init-param>
<param-name>debug</param-name>
<param-value>0</param-value>
</init-param>
<init-param>
<param-name>listings</param-name>
<param-value>false</param-value>
</init-param>
<load-on-startup>1</load-on-startup>
</servlet>And restart your server. This will affect every directory on the server, and return a 405 directory browsing forbidden error.
Another way, is to place an index.jsp inside each directory with a simple one line redirect to your applications CONTEXT_PATH.response.sendRedirect("http://yourserver/yourapp/");This will only affect specific directories which contain these index.jsp files.
Hope this helps -
Need to change the directory using the java program
hi,
can anyone give me the code to change the directory in the java program by using the system command.
as in C where we use the system call system("cd");
the same way how to do that in java. please help me with that!!!Please search the forums for "runtime.exec", there are dozens of examples posted.
Although this may not do you any good, since changing the os's directory is not likely to change anything you're using in Java. What are you trying to do? -
Implementing circular-left shift in java
i'm an fresher currently in a project on SHA algorithm
i would like to know how to implement circular left shift in java
whether there is any method in java to implement this ,
if in case what package i have to import.
please reply me,
yours sincerely
hari hara ganesh.d
indiaint number= ...;
int shift= ...;
int rotleft= (number<<shift)|(number>>>32-shift);kind regards,
Jos -
Newbie: IBM Directory Server LDAP Java Implementation
Good day friends,
I'm new in developing LDAP applications. I'm using IBM Directory Server v4.1 & need to develop a application (a web application - JSP/Servlet/EJB). I'm doing this as part of a Web project where i need to store the User Info of the registering user to LDAP server with proper Organisational Hierarchy & Privileges. I'm using Java for this application. I have the proper JNDI environment set for LDAP interaction. Can anyone provide me with a best practice/right procedure for implementing this, like searching for an entry, inserting/updating an entry & how to make use of Attributes provided in IBM DS 4.1.
I searched IBM redbook & others for this but without any success. All Prog references are pertaining to C & very minimal info for Java implementation. I found some info in other LDAP like Netscape & Novell, but there structuring is different from IBM DS. I would appreciate if anyone can throw some light on this regard. I would appreciate a complete Java Programmers Reference Guide for IBM Directory Server v4.1.
Thanking u in anticipation.
cheers,
J2EEDev.I'm coping with the same question as you had.
Did you get any valuable information or a Java programmers reference guide for IBM directory server ?
If so, could you send me an url where I can obtain the required information ?
Thanks for your reply !
Dirk -
Oracle Workflow Manager, Agent Listener, and Java Mailer problem
Hi,
I am not sure this topic to this forum, since this might be installation issue.
But I am hitting a big wall.
I had Windows 2000 SP4.
I have already installed Oracle Database 10gR1, Oracle Developer 10gR2, and Oracle Workflow 2.6.3 Standalone previously.
Including :
- Oracle Workflow Server 2.6.3
- Oracle Workflow Builder 2.6.3.5
- Apache HTTP Server 9.0.4
- Workflow Middle Tier
Anything seems to right, including the Notification Mailer and the Business Event.
And I had also made backup of them surely.
Now,
I'd like to change into Oracle Database 10gR2 because :
1. Some errors I found when I tried to call a Report from Oracle Form.
Unable to connect to Report Server ...
I thought Oracle Database 10gR1 is not suitable for Oracle Developer 10gR2.
2. And in the OWF 2.6.3 Workflow Home Page, there was no Logout button (which I found in OWF 2.6.4)
I removed my previous installation including Oracle Workflow.
After strugglineg in the installation of Oracle Database 10gR2, now I am facing another problem with Oracle Workflow.
I succesfully installed Oracle Workflow 2.6.4 Server and Oracle Workflow Manager (standalone version),
and the Oracle Workflow Middle Tier.
After I launch Oracle Workflow Configuration Assisstant, everthing seems to be normal.
I succed to open the Oracle Workflow Home Page (and found the Logout button there)
Next, I tried to navigate to the Oracle Workflow Manager.
1. I start the OC4J_Workflow_Management_Container --> initialized
2. OC4J_Workflow_Component_Container
The following error line appeared in the OC4J command prompt
06/05/26 10:31:40 LOG_ID_UNKNOWN : oracle.apps.fnd.cp.gsc.Logger.Logger(String,
int) : Logging to System.out until necessary parameters are retrieved for Logger
to be properly started.
06/05/26 10:31:40 LOG_ID_UNKNOWN : oracle.apps.fnd.cp.gsc.SvcComponentContainer.
initializeStateMachine() : BEGIN [default implementation]
06/05/26 10:31:40 LOG_ID_UNKNOWN : oracle.apps.fnd.cp.gsc.SvcComponentContainer.
getNewWorkflowContext() : BEGIN
06/05/26 10:31:45 LOG_ID_UNKNOWN : oracle.apps.fnd.cp.gsc.SvcComponentContainer.
loadGlobalParameters() : BEGIN
06/05/26 10:31:48 oracle.apps.fnd.wf.common.ContextFactoryException: Unable to g
et connection from data source because the following Exception occurred -> java.
sql.SQLException: ORA-28000: the account is locked
06/05/26 10:33:57 Oracle Application Server Containers for J2EE 10g (9.0.4.1.0)
initialized
3. finally it initialized
Next I tried to go to Oracle Workflow Manager from related link of Enterprise Manager
It is said that the OWF_MGR is locked
(I surprised since I had UNLOCKED the OWF_MGR after the installation and succeed to login at the Workflow Home Page)
And the following error line appeared in the commaned prompt after that
06/05/26 10:35:03 OrionCMTConnection not closed, check your code!
06/05/26 10:35:03 Logical connection not closed, check your code!
06/05/26 10:35:03 (Use -Djdbc.connection.debug=true to find out where the leaked
connection was created)
4. I re-UNLOCK the OWF_MGR and login to Oracle Workflow Manager
I noticed that the Agent Listener and Notification Service is Unavailable
(In OWF 2.6.3, The Agent Listener was started and Notification Service was waiting to be configured)
I tried to start one of the Agent Listener, but the following error appeared
ERROR: The Service Component Container is not running
Well, I had the same problem when installing the OWF 2.6.3
I tried to uninstall (remove) and re-install it like I had done before in OWF 2.6.3
(based on someone's post in Oracle's forum)
But this time, the re-installation won't fix this problem. (It was succeed in the OWF 2.6.3)
Everytime I start the OC4J, using wfmgrstart.bat and wfsvcstart.bat
the OWF_MGR is re-LOCKED(TIME) automatically.
And the servlet (WFALSNRSVC and WFMLRSVC) are not running.
I am worry, since I cannot use the Notification Mailer if this problem had not fixed yet.
(In OWF 2.6.3, the mailer was not available until those servlet is Started)
Sorry for the long post.
Any help would be grateful.
Many thanks,
BuntoroHi,
Finally, I have found the solution.
Step :
1. Start all of the Oracle Service, except for the OC4J
If you have already started OC4J, then stop them
Unlocked the <wf_manager_user>
2. Search in your Oracle Home : data-sources.xml
There should be two files,
one is in the ...\OC4J_Workflow_Component_Container\application-deployments\WFALSNRSVCApp
the other is in ...\OC4J_Workflow_Component_Container\application-deployments\WFMLRSVCApp
3. Make sure, you create back up of them.
4. Replace the following line
password="->pwForOwfMgr"
with
password="<your_wf_manager_password>",
should be look like this
password="a"
5. Now start the OC4J using wfmgrstart.bat and wfsvcstart.bat
6. Next, login to the Oracle Workflow Manager
This worked for me.
Hope this will help someone who has the same problem.
Buntoro
Maybe you are looking for
-
Hi, I wrote the function in formula column, the return value should show in the separate column. Thx, BalajiV
-
Can I use a Samsung HM1100 to play music from my Ipad2?
Can I use my Samsung HM1100 to play music from my Ipad2 ?
-
Hi Experts, I want config document for MM module to know more deatils about configuretion in SAP. Can anyone help me. Regards, Parag.
-
How to update information, on podcasts? Name, etc.
I recently posted a pod cast but ended up not getting the title I wanted. I also would like to add some other detail type of information that has been left blank like "By". Anyone know if we can edit our podcast page through iTunes not just the RSS f
-
How do I download my "entire" photoshop cloud library to my new mac computer?
I have a new iMac and want to download my entire photo library (approximately 8GB) stored in photoshop cloud, directly to my mac hard drive, or i.e. "my pictures" file. Please help... All I can find is how to upload or download individual pics.