Problem with file searching

I m trying to create a website using jsp . In that course i hav to search files (in the same or other directory) . how to do that.
plz help

Check out my Find.java class. It might be close to what you want
You are welcome to use and modify this class, but please don't change the package or take credit for it as your own work.
Find.java
=======
* Created on Jul 8, 2005 by @author Tom Jacobs
package tjacobs.io;
import java.io.File;
import java.util.ArrayList;
import java.util.Collections;
import java.util.Iterator;
import java.util.List;
import java.util.Observable;
import java.util.Observer;
import java.util.Set;
import java.util.TreeSet;
import java.util.regex.Matcher;
import java.util.regex.Pattern;
//import tjacobs.util.Observable;
* Find is pretty groovy. The point of it is to find files ala windows search.
* doesn't have the advanced search options tho.
* Extends Observable so all you need to do is add an observer to it.
public class Find extends Observable implements Runnable {
     private Thread mMyThread;
     private Pattern mPattern;
     private String mDirContains;
     private File mStartDir;
     private boolean mDescOnly = false;
     private List<File> mMatches = new ArrayList<File>();
     private List<File> mDirectoriesToSearch = new ArrayList<File>();
     private Set<String> mDirectoriesSearched = new TreeSet<String>();
     private boolean mStop;
     private boolean mPause;
     public static final boolean DEBUG = false;
     private Find(Pattern pattern, File dir, boolean desc) {
          super();
          mPattern = pattern;
          mStartDir = dir;
          mDescOnly = desc;
     public int size() {
          return mMatches.size();
     public File get(int i) {
          return mMatches.get(i);
     public Iterator<File> iterator() {
          return Collections.unmodifiableList(mMatches).iterator();
     public static Find fsFind(Pattern pattern, File startDir) {
          return fsFind(pattern, startDir, false);
     public static Find fsFind(String pattern, File startDir, boolean descendOnly) {
          return fsFind(Pattern.compile(pattern), startDir, descendOnly);
     public static Find fsFind(Pattern pattern, File startDir, boolean descendOnly) {
          Find find = new Find(pattern, startDir, descendOnly);
          Thread t = new Thread(find, "Find");
          t.setDaemon(true);
          t.start();
          return find;
     public static Find fsFind(String pattern, File startDir) {
          return fsFind(Pattern.compile(pattern), startDir);
     public static Find fsFind(Pattern pattern, String startDir) {
          return fsFind(pattern, new File(startDir));
     public static Find fsFind(String pattern, String startDir) {
          return fsFind(Pattern.compile(pattern), startDir);
     public static Find fsFind(String pattern, String startDir, boolean descendOnly) {
          return fsFind(Pattern.compile(pattern), startDir, descendOnly);
     public static Find fsFind(Pattern pattern, String startDir, boolean descendOnly) {
          return fsFind(pattern, new File(startDir), descendOnly);
     public static Find fsFind(String pattern) {
          return fsFind(Pattern.compile(pattern));
     public static Find fsFind(Pattern pattern) {
          return fsFind(pattern, (File)null);
     public void join() {
          try {
               while (mMyThread == null) {
                    Thread.yield();
               mMyThread.join();
          catch (InterruptedException ex) {
               //TODO: Log this
     public synchronized void addObserver(Observer o) {
          if (o == null) return;
          int size = size();
          for (int i = 0; i < size; i++) {
               o.update(this, get(i));
          super.addObserver(o);
//          super.addObserver(o);
//          if (mMatches != null && mMatches.size() > 0) {
//               for (int i = 0; i < mMatches.size(); i++) {o.update(this, mMatches.)
     public void run() {
          mStop = false;
          mMyThread = Thread.currentThread();
          if (mStartDir == null) {
               mStartDir = new File(".");
          mStartDir = mStartDir.getAbsoluteFile();
          if (mStartDir.isDirectory()) {
               mDirectoriesToSearch.add(mStartDir);
          else {
               mDirectoriesToSearch.add(mStartDir.getParentFile());
          while (mDirectoriesToSearch.size() > 0 && !mStop) {
               if (mPause) {
                    synchronized(this) {
                         try {
                              wait();
                         catch (Exception ex) {ex.printStackTrace();}
               File toSearch = mDirectoriesToSearch.remove(0);
               //mDirectoriesSearched.add(toSearch.getAbsolutePath());
               search(toSearch);
     private void addToMatches(File dir) {
          mMatches.add(dir);
          notifyObservers(dir);
     private void search(File dir) {
          if (DEBUG) System.out.println("dir = " + dir);
          if (mDirectoriesSearched.contains(dir.getAbsolutePath())) {
               return;
          mDirectoriesSearched.add(dir.getAbsolutePath());
          if (!mDescOnly) {
               File par = dir.getParentFile();
               if (par != null) mDirectoriesToSearch.add(par);
          Matcher matcher = mPattern.matcher(dir.getName());
          if (matcher.matches()) {
               addToMatches(dir);
          boolean shouldMatch = true;
          if (mDirContains != null) {
               shouldMatch = dir.getAbsolutePath().toLowerCase().contains(mDirContains);
          File files[] = dir.listFiles();
          if (files == null) {
               return;
          for (int i =0; i < files.length; i++) {
               if (files.isDirectory()) {
                    if (DEBUG) {
                         System.out.println("adding to search: " + files[i]);
                    mDirectoriesToSearch.add(files[i]);
               else if (shouldMatch) {
                    matcher = mPattern.matcher(files[i].getName());
                    if (DEBUG) {
                         System.out.println ("Testing: " + files[i].getName());
                    //String name = files[i].getName();
                    if (matcher.matches()) {
                         super.setChanged();
                         addToMatches(files[i]);
     public void setDirContains(String str) {
          mDirContains = str.toLowerCase();
     public String getDirContains() {
          return mDirContains;
     public void pause() {
          mPause = !mPause;
          if (!mPause) {
               synchronized(this) {
                    notify();
     public void stop() {
          mStop = true;

Similar Messages

  • Unable to download from AppStore, updates,etc.Messages 'the installer is damaged' to 'there might be a problem with file ownership and permissions.' I am the owner and only user of a new MBP. What could be going on?

    Is anyone having the same type of problems I'm having with Lion. I have a new MacBook Pro, received 7 weeks ago, preinstalled with Leopard 10.6.7. I didn't migrate anything from my old iMac, wanted a clean install from the Apple Store. While there, I asked for the upgrade to Lion 10.7, however their system was down.
    I  installed it myself, wirelessly about a week later, and Apple emailed me a receipt. Now, I've had to call support directly last week when I lost Mail, Address Book, was unable to open Preview or iTunes, among other problems. Seemed fixed after a session that baffled even the store tech.  Now I am unable to download or install the recent Mac updates for Lion, from the App Store, could not install Adobe Reader, etc. Messages range from 'A network error has occured - Check your Internet connection and try again' to 'The Installer is damaged and cannot open the package. There may be a problem with file ownership or permissions.'  All fail and I'll probably have to call Apple again. I am frustrated beyond words.  Logs 'Install's runner tool is not properly configured as a setuid tool', domain errors, 'attempt to write a readonly database, and on and on. I have barely done a thing on this computer except search online for help with these problems. Safari gives me a 'You are not connected to the internet' too often. Diagnostics disagrees. I do see wi-fi problems in the forum. Disk and permissions were fine at the beginning of the earlier problems, checked first by support tech. I'm not sure if support tech even knew. I was just happy they were fixed. Anyone have these download and/or install problems after a 'clean bill of health' so to speak, only a week ago?

    Let's try the following user tip with that one:
    "There is a problem with this Windows Installer package ..." error messages when installing iTunes for Windows

  • Problem with file path in linux

    hi,
    i have problem with file path accessing in linux. my java class is accessing a abc.cvs file and and getting all data. it is working fine in windows xp. but i run this same file in linux it does not access the abc.cvs file and does not get any data.
    my project structure
    Search
    abc.cvs
    search.SearchMain
    i am sccessing this cvs file in this SearchMain class by this way file name = "abc.cvs"
    It is working fine with window but problem with linux.
    when i place this abc.cvs in a folder as "./data/abc.cvs" also working fine with windows but not in linux.
    I am new for linux.
    Please give me solution.
    Thanks in advance
    Ravi

    forgot to tell,
    then you need to export that path
    export $CLASSPATH
    code}                                                                                                                                                                               

  • This message [Ubuntu repositories or Mozilla download: " There is no Profile folder Could not initialize the application's security component. The most likely cause is problems with files in your application's profile directory....

    Ubuntu 11.04: I have been getting this message whenever I install Firefox from the repositories and downloading the tar file. I cannot use Firefox! " There is no Profile folder Could not initialize the application's security component. The most likely cause is problems with files in your application's profile directory. Please check that this directory has no read/write restrictions and your hard disk is not full or close to full. It is recommended that you exit the application and fix the problem. If you continue to use this session, you might see incorrect application behaviour when accessing security features."Firefox does not respond to any addresses or a google search. Indeed it responds to nothing. There is no Profile folder!

    Uninstalling Firefox on Linux
    * http://kb.mozillazine.org/Uninstalling_Firefox#On_Linux
    * http://kb.mozillazine.org/Installation_directory#Linux
    * Removing user profile data - http://kb.mozillazine.org/Uninstalling_Firefox#Removing_user_profile_data
    After all is done, Restart your system.
    Installing Firefox on Linux
    * https://support.mozilla.com/en-US/kb/Installing%20Firefox%20on%20Linux
    Check and tell if its working.

  • Why  would an error pop up saying the installer is damaged. The Installer can't open the package. There may be a problem with file ownership or permissions. when trying to install java 7?

    why  would an error pop up saying the installer is damaged. The Installer can’t open the package. There may be a problem with file ownership or permissions. when trying to install java 7?

    Launch the Console application in any of the following ways:
    ☞ Enter the first few letters of its name into a Spotlight search. Select it in the results (it should be at the top.)
    ☞ In the Finder, select Go ▹ Utilities from the menu bar, or press the key combination shift-command-U. The application is in the folder that opens.
    ☞ Open LaunchPad. Click Utilities, then Console in the icon grid.
    Select
    /var/log ▹ install.log
    from the hierarchical list on the left. If you don't see that list, select
    View ▹ Show Log List
    from the menu bar. Then select the messages from the last installation or update attempt, starting from the time when you initiated it. If you're not sure when that was, click the Clear Display button in the toolbar of the Console window and then try the installation again.
    Copy the messages to the Clipboard by pressing the key combination command-C. Paste into a reply to this message (command-V).
    If there are runs of repeated messages, post only one example of each. Don’t post many repetitions of the same message.
    When posting a log extract, be selective. Don't post more than is requested.
    Please do not indiscriminately dump thousands of lines from the log into this discussion.
    Important: Some private information, such as your name, may appear in the log. Edit it out by search-and-replace in a text editor before posting.

  • A problem with file-roller!!!

    I have a problem with file-roller.
    When I open an achieve file with file-roller, I can not directly open the file in the file-roller. "Open with" does not work either.
    But if i use sudo for file-roller, "open" and "open with" do work.
    How can I use "open" and "open with" without sudo for file-roller?
    Can any body help me ?

    Hi,
    The link is working... it's not a nautilus quirk. Try these examples:
    FIRST EXAMPLE:
    Login as root and edit mimeinfo.cache (In openSUSE, the linux distribution I'm using right now, this file is placed on /usr/share/applications).
    su
    gedit /usr/share/applications/mimeinfo.cache
    Search for audio/mpeg=
    The first application I specify is going to be the program that File-Roller will use to open a compressed mp3 file.
    Example:
    audio/mpeg=totem.desktop;banshee-1.desktop;
    This will open Totem...
    audio/mpeg=banshee-1.desktop;totem.desktop;
    This will open Banshee.
    SECOND EXAMPLE:
    $ su
    $ gedit /usr/share/applications/defaults.list
    Search for:
    text/xml=MozillaFirefox.desktop
    Replace to:
    text/xml=gedit.desktop
    This will open xml files with Gedit, instead of Firefox.
    Good luck.
    Last edited by kuric (2008-11-22 16:49:30)

  • What's problem with File Panel?

    Hi All!
    I'm web designer, while developing my site, my work is
    breaking a problem with File management of DMX.
    First, I develop site in DMX8 (ASP + SQL), then when I open
    that site in DMXCS3 - Note: all file still in only one Folder in
    HDD on (D\: Drive), (example: photo-editor.asp), this file content
    is last time modify. And when I open again this file in DMX8 - the
    file content of this file (photo-editor.asp) not same with new
    version in DMXCS3. It is old version!.
    I don't understand why that. (note: I don't check Enable
    cache in Local info in Site Definition). Please help me about this
    problem!
    Thank for All!

    Are both versions (DW8 and DWCS3) using the SAME local site?
    Look in your
    site definition in both versions of DW, and tell us what the
    path is to the
    local root folder, please.
    Murray --- ICQ 71997575
    Adobe Community Expert
    (If you *MUST* email me, don't LAUGH when you do so!)
    ==================
    http://www.dreamweavermx-templates.com
    - Template Triage!
    http://www.projectseven.com/go
    - DW FAQs, Tutorials & Resources
    http://www.dwfaq.com - DW FAQs,
    Tutorials & Resources
    http://www.macromedia.com/support/search/
    - Macromedia (MM) Technotes
    ==================
    "alonehero" <[email protected]> wrote in
    message
    news:fao4vg$n25$[email protected]..
    > Hi All!
    >
    > I'm web designer, while developing my site, my work is
    breaking a problem
    > with
    > File management of DMX.
    >
    > First, I develop site in DMX8 (ASP + SQL), then when I
    open that site in
    > DMXCS3 - Note: all file still in only one Folder in HDD
    on (D\: Drive),
    > (example: photo-editor.asp), this file content is last
    time modify. And
    > when I
    > open again this file in DMX8 - the file content of this
    file
    > (photo-editor.asp)
    > not same with new version in DMXCS3. It is old version!.
    >
    > I don't understand why that. (note: I don't check Enable
    cache in Local
    > info
    > in Site Definition). Please help me about this problem!
    >
    > Thank for All!
    >

  • Newbie : memory problem with file uploading

    Hello
    I'm exdending a web app based on jsf and , being new to it and java in general, i'm having a problem with file uploading.
    The customer needs to upload large file (more than 30 MB). The application accomplish this using a fileupload component, to let the user select the file, and passing the array of bytes to a web service method.
    I'm using netbeans 6, tomcat 5.5.
    When i try to upload a file too large i got an outofmemory on the local tomcat. So i've rised jvm memory and going on with tests i've found that growing the size i got an http 500 error from the service (the developer of the service has found an out of memory too ).
    I think the service is not modifiable, so i were asking if threre were a way to optimize the file uploading process (a component, a library, a pattern ...) or my only chioice is to rise available memory on both sides.
    I've notice the wsdl declares as base64binary type the data parameter , while netbeans 6 generates a client proxy with a byte[] parameter. Is correct or is a netbeans problem?
    searching with google i've found few thing i haven't fully understood due to my lack of experience:
    the mtom , how can evaluate if it's suitable to help in my problem (i suppose it involves more the web service rather than the client)
    something about the size of a soap body.
    thank you in advance
    Stefano

    Which component exactly are you using? Declaring the stream as a raw byte[] is certainly not efficient. Write code yourself, don't let it autogenerate.
    I can highly recommend you the Tomahawk t:inputFileUpload component. It is easy to integrate in Mojarra. You can find here an useful article: [http://balusc.blogspot.com/2008/02/uploading-files-with-jsf.html].

  • Problems with File Transfers Over Firewire 800

    Problems with File Transfers Over Firewire 800.
    Over the past month, I have had problems when transfering files from my harddrive, over Firewire 800 to a portable drive. I usually transfer very large files (20gb or more) to the portable drives for moving files around. When I drag a file over to copy onto a drive, the transfer starts normally. If I drag more files to copy over, the computer screen goes darker and a large icon comes up that looks like a power button icon. It tells me to restart, so I have to do a hard shut down on my G5. Weird. I also get the dark screen of death sometimes when I am transfering those large files and open another application to do some work while it's copying. It's killing me. I am having to sit here and wait for the transfer to finish before I can do anything.
    Any thoughts...
    Dual 2.7 GHz PowerPC G5
    Mac OSX 10.4.3
    Dual 2.7 GHz PowerPC G5   Mac OS X (10.4.3)  

    Have you run the Apple Hardware Test? Sounds like it could be a RAM problem.

  • Error while opening pdf in reader in windows 8:Can't open this file. There's a problem with file format

    I have a problem with a pdf file which does not open with reader in windows 8 but it opens properly with adobe pdf reader. All other pdf can be opened in reader.But when i open a pdf(see this link for pdf for which i got error http://incometaxsoft.com/temp/Form.pdf)
    it gives error as "Can't open this file. There's a problem with file format".
    The same file opens properly in adobe pdf reader.You can check the pdf file which i have mentioned in the link above.But the reader which comes with windows 8 can open some other pdf in the same PC.What may be the error causing this??

    This has turned out to be an enormous issue for me as I sell PDF files as ebooks. I have done a fair amount of investigating this for my system.
    My files have to be compatible not just across readers but across operating systems.
    To date, I have over 200 PDFs that have functioned flawlessly across Mac, PC (Windows 7 and below), Android, iPhone/iPad, Linux.
    I personally test my PDFs using a variety of readers and PDF editors including
    PDF XChange (my favorite)
    Foxit (runner up for me and I recommend for most people)
    Adobe (the bloated monster)
    Nitro 9 (great for moving graphical elements around)
    ABBYY
    And the Nuance PDF Create toolsets
    Those are off the top of my head. There are a bunch on Android that I test with too.
    I am running the Windows 10 Pro Tech Preview and I have this same problem so I know it isn't fixed yet in any kind of pre-release way (-sigh-)
    Here is what I've learned for my situation
    The PDFs I created using NUANCE'S PDF CREATE PROFESSIONAL VERSION 8
    all fail using the built-in Windows 8/10 PDF reader.
    When I look at the PDF properties for these Nuance created files, the underlying engine used to write them is called "ImageToPDF". Using ABBYY it indicates their own engine as does everyone else that I've tried. It is easy for you to check to see
    what created your PDF by doing a "Control D" (look at the document properties). Perhaps there's a common engine causing issues.
    If I use the exact same source files to create a PDF using any of my other tools I have no issues. I checked the PDF versions made by the tools and they are all set to 1.5.
    A customer mentioned being able to convert them in a way they worked by saving them without having to do any kind of extraction, but I have not been able to duplicate that. Perhaps he did a "print" which seems like it could work.
    In summary, the workaround everyone is talking about, using an alternate reader, of course works. But not everyone wants to change.
     The culprit I have found is my Nuance PDF Creation tools that are using the ImageToPDF engine.
    I hope it gets FIXED as I really don't want to have to regenerate all of my PDF files.

  • I suddenly have this error message on FireFoxthis message pops up: "Could not initialize the application's security component. The most likely cause is problems with files in your application's profile directory. Please check that this directory has no re

    I suddenly encounter this error message from Fire Fox.
    Could not initialize the application's security component. The most likely cause is problems with files in your application's profile directory. Please check that this directory has no read/write restrictions and your hard disk is not full or close to full. It is recommended that you exit the application and fix the problem. If you continue to use this session, you might see incorrect application behaviour when accessing security features.
    I uninstalled the browser and download a new version but it does not resolve the issue.
    I know my hard disc has ample space. I do NOT know where to find the Profile directory to fix the read restriction box.
    == This happened ==
    Every time Firefox opened
    == After something about security add-on of Norton pop up by itself. ==
    == User Agent ==
    Mozilla/4.0 (compatible; MSIE 7.0; Windows NT 5.1; MSN Optimized;US)

    This link shows things to check - https://support.mozilla.com/kb/Could+not+initialize+the+browser+security+component

  • Problem with File Based replication in Weblogic Express 10

    Hi,
              We have Web application (exploded war) file deployed on Weblogic Express 10, to a Cluster of three Managed Servers (all three on different physical machines).
              We are using File based session persistance in weblogic.xml
              We have a shared location for all the three servers where we will be sharing the Session data.
              When we start the application, its works fine and is very fast, but after sometime the application slows down.
              Troubleshooting the Issue we found that its a problem with file based replication. By using File based replication every user session is stored in form of directory inside shared directory. So after sometime thousands of directories are created inside the shared directory where the session information is stored. So when we access the application, its waiting for lot of time with Message Session Monitor .... (this is because its browsing through the shared session storage directory for lot of time for session information as it has lot of directories) and finally after a long time like 10 mins we get the Application Home Page.
              When we clean up all the saved sessions inside shared directory, the application works fine, But we will see the same sometime later may be after 3 or 4 hours when the shared session directory has lot of session information stored in it.
              Is there a way to clean up the saved session information on file system as soon as that user session is closed by using file based replication.
              We cannot used Inmemory replication as our Appl doesnt support it.
              Please advice as it is a major show stopper in our Production Mirror env.
              Weblogic Consultant

    It is possible to reduce number of live session by configuring very low timeout-secs weblogic.xml. Default is 60 minutes.
              More details are here..
              http://e-docs.bea.com/wls/docs100/webapp/weblogic_xml.html#wp1071982
              Jayesh
              Yagna Sys

  • Problem with file permissions

    Hello all,
    I am making a simple HttpServlet, which takes input
    from html page and saves in to a file, but I'm having a
    bit of a problem with file permissions.
    I'm getting the following exception
    java.security.AccessControlException: access denied (java.io.FilePermission ./data/result read)
         java.security.AccessControlContext.checkPermission(AccessControlContext.java:264)
         java.security.AccessController.checkPermission(AccessController.java:427)
         java.lang.SecurityManager.checkPermission(SecurityManager.java:532)
         java.lang.SecurityManager.checkRead(SecurityManager.java:871)
         java.io.File.exists(File.java:700)
         SyksyHTTPServlet.doPost(SyksyHTTPServlet.java:31)
         javax.servlet.http.HttpServlet.service(HttpServlet.java:709)
         javax.servlet.http.HttpServlet.service(HttpServlet.java:802)
         sun.reflect.GeneratedMethodAccessor52.invoke(Unknown Source)
         sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:25)
         java.lang.reflect.Method.invoke(Method.java:585)
         org.apache.catalina.security.SecurityUtil$1.run(SecurityUtil.java:243)
         java.security.AccessController.doPrivileged(Native Method)
         javax.security.auth.Subject.doAsPrivileged(Subject.java:517)
         org.apache.catalina.security.SecurityUtil.execute(SecurityUtil.java:275)
         org.apache.catalina.security.SecurityUtil.doAsPrivilege(SecurityUtil.java:161)The exception seems to occur when I'm trying to check whether the file already
    exists or not.
    The data directory has all permissions (read, write and execute) set for all users,
    and I have made an empty file called result inside the data directory for testing.
    This file has read and write permissions enabled for all users.
    Here's my code
    import javax.servlet.*;
    import javax.servlet.http.*;
    import java.io.*;
    import java.util.Enumeration;
    import java.util.List;
    import java.util.ArrayList;
    public class SyksyHTTPServlet extends HttpServlet
         public void doPost(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException
              int totalCount = 0;
              List list;
              String song = request.getParameter("song");
              PrintWriter out = response.getWriter();
              File file = new File("./data/result");
              if(file.exists())  // this is line 31, which seems to cause the exception
                   list = readFile(file);
              else
                   file.createNewFile();
                   list = new ArrayList();
              list.add(song);
              writeFile(file, list);
              for(int i = 0 ; i < list.size() ; i++)
                   out.println(list.get(i));
         public void doGet(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException
              doPost(request, response);
         private List readFile(File file)
              List list = null;
              try
                   FileInputStream fis = new FileInputStream(file);
                   ObjectInputStream ois = new ObjectInputStream(fis);
                   list = (ArrayList)ois.readObject();
                   ois.close();
              catch(Exception e)
                   e.printStackTrace();
              return list;
         private void writeFile(File file, List list)
              try
                   FileOutputStream fos = new FileOutputStream(file);
                   ObjectOutputStream oos = new ObjectOutputStream(fos);
                   oos.writeObject(list);
                   oos.flush();
                   oos.close();
              catch(Exception e)
                   e.printStackTrace();
    }I'm using Tomcat 5.5 on Ubuntu Linux, if that has anything to do with this.
    I'll appreciate all help.
    kari-matti

    Hello again.
    I'm still having problems with this. I made
    a simple servlet that reads from and writes
    to text file. The reading part work fine on my
    computer, but the writing doesn't, not even
    an exception is thrown if the file exists that
    I'm trying to write to. If I try to create a new
    file I'll get an exception about file permissions.
    I also asked a friend of mine to try this same
    servlet on his windows computer and it works
    as it should.
    Here's the code
    import javax.servlet.*;
    import javax.servlet.http.*;
    import java.io.*;
    public class ReadServlet extends HttpServlet
         public void doPost(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException
              String s = "";
              PrintWriter out = response.getWriter();
              String docroot = getServletContext().getRealPath( "/" );
              out.println("docroot: "+docroot);
              File file = new File(docroot+"test.txt");
              if(file.exists())
                   s = readFile(file);
                   out.println(s);
              else
                   out.println("file not found");
                   //file.createNewFile();                    // causes exception
                   //out.println("new file created.");
              writeFile(file, "written by servlet");
              out.println("Now look in the file "+file.getPath());
              out.println("and see if it contains text 'written by servlet'");
         public void doGet(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException
              doPost(request, response);
         private String readFile(File file)
              FileInputStream fis = null;
              BufferedInputStream bis = null;
              DataInputStream dis = null;
              String s = "";
              try
                   fis = new FileInputStream(file);
                   bis = new BufferedInputStream(fis);
                   dis = new DataInputStream(bis);
                   s = dis.readLine();
                   fis.close();
                   bis.close();
                   dis.close();
              catch(Exception e)
                   e.printStackTrace();
              return s;
         private void writeFile(File file, String s)
              FileOutputStream fos = null;
              BufferedOutputStream bos = null;
              DataOutputStream dos = null;
              try
                   fos = new FileOutputStream(file);
                   bos = new BufferedOutputStream(fos);
                   dos = new DataOutputStream(bos);
                   dos.writeChars(s);
                   fos.flush();
                   bos.flush();
                   dos.flush();
                   fos.close();
                   bos.close();
                   dos.close();
              catch(Exception e)
                   e.printStackTrace();
    }And if someone wants to test this servlet I can
    give a war package.
    Any advices?
    kari-matti

  • Problem with File Content Conversion

    Hi All
    I am facing a problem with file content conversion.
    This is my sample file structure:
    Header_Record (Occurance - 1)
    Field1 in Header
    Field2 in Header
    Item(Occ-1 to n)
    Field3 in Item
    Field4 in Item
    <<ItemType>> (Structure in Item) (Occ - 0 to n)
    <<Field5>> in ItemType
    <<Field6>> in ItemType
    <<ItemTypeCategory>> (Structure in ItemType)(Occ - 0 to n)
    <<<<Field7>>>> in ItemTypeCategory
    <<<<Field8>>>> in ItemTypeCategory
    Footer_Record (Occurance-1)
    Field9
    Field10
    There is a key field 'Type' in all the above records with unique value in each record.
    Now, I defined Field content conversion as follows:
    Recordset Structure: Header_Record,1,Item, * , ItemType, * ,ItemTypeCategory, * ,Footer_Record,1
    Recordset Sequence: Ascending
    KeyField Name: Type
    Following are parameters defiled:
    Header_Record.Keyfieldvalue: 00
    Header_Record.fieldseperator: ,
    Header_Record.fieldnames: Field1,Field2
    Header_Record.endseperator: 'nl'
    Item.keyfieldvalue: 05
    item.fieldseperator: ,
    item.fieldfieldnames: field3,field4
    item.endseperator: 'nl'
    ItemType.keyfieldvalue: 10
    itemType.fieldseperator: ,
    itemType.fieldfieldnames: field5,field6
    itemType.endseperator: 'nl'
    ItemTypecategory.keyfieldvalue: 15
    itemTypecategory.fieldseperator: ,
    itemTypecategory.fieldfieldnames: field7,field8
    itemTypecategory.endseperator: 'nl'
    Footer.keyfieldvalue: 20
    Footer.fieldseperator: ,
    Footer.fieldfieldnames: field5,field6
    Footer.endseperator: 'nl'
    Now, i pass the following file:
    00,111
    05,222
    10,333
    15,444
    20,555
    What i expect out of my FCC is this (Sample output to show the hierarchy of field values):
    00,111
    05,222
    <<10,333>>
    <<<<15,444>>>>
    20,555
    But, I am getting this output (Hierarchy is missing. All the structures are in the same order without hierarchy):
    00,111
    05,222
    10,333
    15,444
    20,555
    Field values are being identified according to field content conversion, but, the hierarchy of the fields is missing.
    Can you please tell me how should i change my FCC config?
    Sorry for this long question.
    Many Thanks
    Chandra
    Edited by: Chandra Sekhar H on Jan 30, 2009 7:10 PM
    Edited by: Chandra Sekhar H on Jan 30, 2009 7:16 PM
    Edited by: Chandra Sekhar H on Jan 30, 2009 7:17 PM

    You will always get a flat structure from FCC. If you want hierarchichal strucuture, you have to create a target and map. You will get only like -
    Root
    --Recordset
    Group1
    Fields
    Grop2
    Fields
    Group3
    Fields
    VJ

  • Problem with file vault

    One of the desktops on my macbook 2007 steel case will not open.
    The message i get on screen at login is that there is a problem with file vault.
    my dissertation is on that desktop.
    all other desktops/user accounts are unaffected and i have admin permissions on them
    i recently upgraded to osx 10.9.4
    how can i get back in?
    chaiman 22

    If you restored the account to which the FileVault protected Home folder belonged, then you need to log into that account and enable FileVault.
    If you just need access to the data in the FV protected Home folder, then locate the sparsebundle disc image file that contains the encrypted folder. Double-click on it as if to mount it. You will then need to enter the FV password associated with the account to gain access (this is NOT the admin nor login password.)

Maybe you are looking for

  • How to get current sesssion information using Webappscontext in servlet?

    Hi, I have an applet embedded in a self-service page (using OAHTMLWebBean). This applet sends information to a servlet, to query the database. I would like to use the session that was created when I logged into Oracle Applications as the session for

  • How to set a consistent footnote in pages 09?

    Hi people, I am currently writing a business report in Pages 09. I want to have on all pages the same footnote and headnote. Now, I have some stuff in the foot and head line of the first page and attached the style to it - but i did not anyything to

  • OBIEE 11.1.1.7.0 failing during starting managed server : bi_server1

    Hi All,       I am trying to install OBIEE 11.1.1.7.1 un a Linux box, but during the Configuration Progress, OBIEE got error at Start Managed server; bi_server1.      Looking into install log I've found the following : Done Stopping Derby Server... S

  • How to install OAS Server Control in 10.1.3.1

    I have a server where OAS 10.1.3.1 is installed and running, but it looks like the OAS Server Control was not part of the initial install. I need to go in and change some timeout settings but am not sure how to get to those settings without the Serve

  • Add Tracking Mask to PSD or .PNG Layer in AE CC

    Guys, I'm pulling my hair out. Anyway you could give me a quick tip on how to apply a tracking mask to a PSD or .PNG layered on top of a movie file in AE CC? Man i'm going crazy trying to figure this out. Thank you very much in advance. I see here: h