String substitution in a file

What is the appropriate strategy to do string substitution within a file. Is it simply loading the contents of the file into a string, do the substitution on the string, then rewrite the string back to the same file? Is there a regex class that performs string substitution on a file?
Thanks

Depends. If the substitute string is the same length, than RandomAccessFile can be use affectively. Otherwise, read in the old file and write out the new one with the changes, then delete the old one.
Regex is avail and is used indirectly via String methods such as replaceAll, etc.
Refer to java.io. and java.lang.string.

Similar Messages

  • Installing JDeveloper on OSX : Fatal Error (during string substitutions)

    Following the instructions from: http://download.oracle.com/docs/cd/E12839_01/install.1111/e13666/ojdig.htm#BDCFFEJC
    and read about all the post in this forum, I am still not able to install JDeveloper 11.1.1.3 or 11.1.1.2
    MacOSX 10.6.5 with Java 1.6.0_22
    I did the steps as mentioned in the installation guide (make sure 64-bit is on top of the list in the java preferences tool + made the link)
    The installer has no problems finding java, but displays a "Fatal Error etc..." at 52%: the action going on then is "Performing String Substitutions"
    The log file looks as follows:
    2010-11-23 22:08:12,639 WARN [getArchivesFromTree] com.bea.cie.gpr.internal.feature.FeatureCatalogImpl - Unable to locate feature corresponding to feature reference: <xml-fragment feature="weblogic.client.modules" feature-version="10.3.3.0"/>
    2010-11-23 22:08:12,676 WARN [getArchivesFromTree] com.bea.cie.gpr.internal.feature.FeatureCatalogImpl - Unable to locate feature corresponding to feature reference: <xml-fragment feature="weblogic.client.modules.L10N" feature-version="10.3.3.0"/>
    2010-11-23 22:08:12,678 WARN [getArchivesFromTree] com.bea.cie.gpr.internal.feature.FeatureCatalogImpl - Unable to locate feature corresponding to feature reference: <xml-fragment feature="weblogic.server.modules" feature-version="10.3.3.0"/>
    2010-11-23 22:08:12,679 WARN [getArchivesFromTree] com.bea.cie.gpr.internal.feature.FeatureCatalogImpl - Unable to locate feature corresponding to feature reference: <xml-fragment feature="weblogic.server.modules.L10N" feature-version="10.3.3.0"/>
    2010-11-23 22:08:12,681 WARN [getArchivesFromTree] com.bea.cie.gpr.internal.feature.FeatureCatalogImpl - Unable to locate feature corresponding to feature reference: <xml-fragment feature="weblogic.server.modules.extra" feature-version="10.3.3.0"/>
    2010-11-23 22:08:12,681 WARN [getArchivesFromTree] com.bea.cie.gpr.internal.feature.FeatureCatalogImpl - Unable to locate feature corresponding to feature reference: <xml-fragment feature="weblogic.saml2.modules" feature-version="10.3.3.0"/>
    2010-11-23 22:08:12,682 WARN [getArchivesFromTree] com.bea.cie.gpr.internal.feature.FeatureCatalogImpl - Unable to locate feature corresponding to feature reference: <xml-fragment feature="weblogic.server.modules.coherence.integration" feature-version="10.3.3.0"/>
    2010-11-23 22:08:12,683 WARN [getArchivesFromTree] com.bea.cie.gpr.internal.feature.FeatureCatalogImpl - Unable to locate feature corresponding to feature reference: <xml-fragment feature="weblogic.server.modules.toplinkgrid" feature-version="10.3.3.0"/>
    2010-11-23 22:08:12,684 WARN [getArchivesFromTree] com.bea.cie.gpr.internal.feature.FeatureCatalogImpl - Unable to locate feature corresponding to feature reference: <xml-fragment feature="com.bea.cie.quickstart" feature-version="10.3.2.0"/>
    2010-11-23 22:08:12,685 WARN [getArchivesFromTree] com.bea.cie.gpr.internal.feature.FeatureCatalogImpl - Unable to locate feature corresponding to feature reference: <xml-fragment feature="com.bea.cie.common-plugin" feature-version="2.5.0.0"/>
    2010-11-23 22:08:12,686 WARN [getArchivesFromTree] com.bea.cie.gpr.internal.feature.FeatureCatalogImpl - Unable to locate feature corresponding to feature reference: <xml-fragment feature="com.bea.cie.common-plugin.launch" feature-version="2.5.0.0"/>
    2010-11-23 22:08:12,687 WARN [getArchivesFromTree] com.bea.cie.gpr.internal.feature.FeatureCatalogImpl - Unable to locate feature corresponding to feature reference: <xml-fragment feature="com.bea.cie.common-plugin.L10N" feature-version="2.5.0.0"/>
    2010-11-23 22:08:12,688 WARN [getArchivesFromTree] com.bea.cie.gpr.internal.feature.FeatureCatalogImpl - Unable to locate feature corresponding to feature reference: <xml-fragment feature="com.oracle.cie.config-security" feature-version="1.0.0.0"/>
    2010-11-23 22:08:12,689 WARN [getArchivesFromTree] com.bea.cie.gpr.internal.feature.FeatureCatalogImpl - Unable to locate feature corresponding to feature reference: <xml-fragment feature="com.oracle.cie.config" feature-version="7.0.0.0"/>
    2010-11-23 22:08:12,690 WARN [getArchivesFromTree] com.bea.cie.gpr.internal.feature.FeatureCatalogImpl - Unable to locate feature corresponding to feature reference: <xml-fragment feature="com.oracle.cie.config.launch" feature-version="10.3.3.0"/>
    2010-11-23 22:08:12,690 WARN [getArchivesFromTree] com.bea.cie.gpr.internal.feature.FeatureCatalogImpl - Unable to locate feature corresponding to feature reference: <xml-fragment feature="com.oracle.cie.config.L10N" feature-version="7.0.0.0"/>
    2010-11-23 22:08:12,693 WARN [getArchivesFromTree] com.bea.cie.gpr.internal.feature.FeatureCatalogImpl - Unable to locate feature corresponding to feature reference: <xml-fragment feature="weblogic.server.modules.pubsub" feature-version="10.3.3.0"/>
    2010-11-23 22:08:12,716 WARN [getArchivesFromTree] com.bea.cie.gpr.internal.feature.FeatureCatalogImpl - Unable to locate feature corresponding to feature reference: <xml-fragment feature="weblogic.server.modules.sca" feature-version="10.3.3.0"/>
    2010-11-23 22:08:12,718 WARN [getArchivesFromTree] com.bea.cie.gpr.internal.feature.FeatureCatalogImpl - Unable to locate feature corresponding to feature reference: <xml-fragment feature="weblogic.server.modules.dotnet" feature-version="10.3.3.0"/>
    2010-11-23 22:08:12,720 WARN [getArchivesFromTree] com.bea.cie.gpr.internal.feature.FeatureCatalogImpl - Unable to locate feature corresponding to feature reference: <xml-fragment feature="weblogic.server.modules.xquery" feature-version="10.3.3.0"/>
    2010-11-23 22:08:12,722 WARN [getArchivesFromTree] com.bea.cie.gpr.internal.feature.FeatureCatalogImpl - Unable to locate feature corresponding to feature reference: <xml-fragment feature="com.bea.cie.gpr" feature-version="3.0.1.0"/>
    2010-11-23 22:08:12,723 WARN [getArchivesFromTree] com.bea.cie.gpr.internal.feature.FeatureCatalogImpl - Unable to locate feature corresponding to feature reference: <xml-fragment feature="com.bea.cie.uninstall" feature-version="6.2.0.0"/>
    2010-11-23 22:08:12,723 WARN [getArchivesFromTree] com.bea.cie.gpr.internal.feature.FeatureCatalogImpl - Unable to locate feature corresponding to feature reference: <xml-fragment feature="com.bea.cie.uninstall.launch" feature-version="6.0.0.0"/>
    2010-11-23 22:08:12,724 WARN [getArchivesFromTree] com.bea.cie.gpr.internal.feature.FeatureCatalogImpl - Unable to locate feature corresponding to feature reference: <xml-fragment feature="com.bea.cie.uninstall.L10N" feature-version="6.2.0.0"/>
    2010-11-23 22:08:12,726 WARN [getArchivesFromTree] com.bea.cie.gpr.internal.feature.FeatureCatalogImpl - Unable to locate feature corresponding to feature reference: <xml-fragment feature="com.bea.cie.patch-client" feature-version="3.2.1.0"/>
    2010-11-23 22:08:12,726 WARN [getArchivesFromTree] com.bea.cie.gpr.internal.feature.FeatureCatalogImpl - Unable to locate feature corresponding to feature reference: <xml-fragment feature="com.bea.cie.patch-client.L10N" feature-version="3.2.0.0"/>
    2010-11-23 22:08:12,728 WARN [getArchivesFromTree] com.bea.cie.gpr.internal.feature.FeatureCatalogImpl - Unable to locate feature corresponding to feature reference: <xml-fragment feature="com.oracle.ocm" feature-version="1.0.0.0"/>
    2010-11-23 22:08:12,729 WARN [getArchivesFromTree] com.bea.cie.gpr.internal.feature.FeatureCatalogImpl - Unable to locate feature corresponding to feature reference: <xml-fragment feature="com.bea.cie.paf" feature-version="1.1.0.0"/>
    2010-11-23 22:08:12,729 WARN [getArchivesFromTree] com.bea.cie.gpr.internal.feature.FeatureCatalogImpl - Unable to locate feature corresponding to feature reference: <xml-fragment feature="com.bea.cie.clone" feature-version="1.1.0.0"/>
    2010-11-23 22:08:13,005 WARN [getArchivesFromTree] com.bea.cie.gpr.internal.feature.FeatureCatalogImpl - Unable to locate feature corresponding to feature reference: <xml-fragment feature="weblogic.client.modules" feature-version="10.3.3.0"/>
    2010-11-23 22:08:13,005 WARN [getArchivesFromTree] com.bea.cie.gpr.internal.feature.FeatureCatalogImpl - Unable to locate feature corresponding to feature reference: <xml-fragment feature="weblogic.client.modules.L10N" feature-version="10.3.3.0"/>
    2010-11-23 22:08:13,007 WARN [getArchivesFromTree] com.bea.cie.gpr.internal.feature.FeatureCatalogImpl - Unable to locate feature corresponding to feature reference: <xml-fragment feature="weblogic.server.modules" feature-version="10.3.3.0"/>
    2010-11-23 22:08:13,008 WARN [getArchivesFromTree] com.bea.cie.gpr.internal.feature.FeatureCatalogImpl - Unable to locate feature corresponding to feature reference: <xml-fragment feature="weblogic.server.modules.L10N" feature-version="10.3.3.0"/>
    2010-11-23 22:08:13,009 WARN [getArchivesFromTree] com.bea.cie.gpr.internal.feature.FeatureCatalogImpl - Unable to locate feature corresponding to feature reference: <xml-fragment feature="weblogic.server.modules.extra" feature-version="10.3.3.0"/>
    2010-11-23 22:08:13,010 WARN [getArchivesFromTree] com.bea.cie.gpr.internal.feature.FeatureCatalogImpl - Unable to locate feature corresponding to feature reference: <xml-fragment feature="weblogic.saml2.modules" feature-version="10.3.3.0"/>
    2010-11-23 22:08:13,011 WARN [getArchivesFromTree] com.bea.cie.gpr.internal.feature.FeatureCatalogImpl - Unable to locate feature corresponding to feature reference: <xml-fragment feature="weblogic.server.modules.coherence.integration" feature-version="10.3.3.0"/>
    2010-11-23 22:08:13,011 WARN [getArchivesFromTree] com.bea.cie.gpr.internal.feature.FeatureCatalogImpl - Unable to locate feature corresponding to feature reference: <xml-fragment feature="weblogic.server.modules.toplinkgrid" feature-version="10.3.3.0"/>
    2010-11-23 22:08:13,015 WARN [getArchivesFromTree] com.bea.cie.gpr.internal.feature.FeatureCatalogImpl - Unable to locate feature corresponding to feature reference: <xml-fragment feature="com.bea.cie.quickstart" feature-version="10.3.2.0"/>
    2010-11-23 22:08:13,015 WARN [getArchivesFromTree] com.bea.cie.gpr.internal.feature.FeatureCatalogImpl - Unable to locate feature corresponding to feature reference: <xml-fragment feature="com.bea.cie.common-plugin" feature-version="2.5.0.0"/>
    2010-11-23 22:08:13,017 WARN [getArchivesFromTree] com.bea.cie.gpr.internal.feature.FeatureCatalogImpl - Unable to locate feature corresponding to feature reference: <xml-fragment feature="com.bea.cie.common-plugin.launch" feature-version="2.5.0.0"/>
    2010-11-23 22:08:13,017 WARN [getArchivesFromTree] com.bea.cie.gpr.internal.feature.FeatureCatalogImpl - Unable to locate feature corresponding to feature reference: <xml-fragment feature="com.bea.cie.common-plugin.L10N" feature-version="2.5.0.0"/>
    2010-11-23 22:08:13,039 WARN [getArchivesFromTree] com.bea.cie.gpr.internal.feature.FeatureCatalogImpl - Unable to locate feature corresponding to feature reference: <xml-fragment feature="com.oracle.cie.config-security" feature-version="1.0.0.0"/>
    2010-11-23 22:08:13,040 WARN [getArchivesFromTree] com.bea.cie.gpr.internal.feature.FeatureCatalogImpl - Unable to locate feature corresponding to feature reference: <xml-fragment feature="com.oracle.cie.config" feature-version="7.0.0.0"/>
    2010-11-23 22:08:13,040 WARN [getArchivesFromTree] com.bea.cie.gpr.internal.feature.FeatureCatalogImpl - Unable to locate feature corresponding to feature reference: <xml-fragment feature="com.oracle.cie.config.launch" feature-version="10.3.3.0"/>
    2010-11-23 22:08:13,041 WARN [getArchivesFromTree] com.bea.cie.gpr.internal.feature.FeatureCatalogImpl - Unable to locate feature corresponding to feature reference: <xml-fragment feature="com.oracle.cie.config.L10N" feature-version="7.0.0.0"/>
    2010-11-23 22:08:13,046 WARN [getArchivesFromTree] com.bea.cie.gpr.internal.feature.FeatureCatalogImpl - Unable to locate feature corresponding to feature reference: <xml-fragment feature="weblogic.server.modules.pubsub" feature-version="10.3.3.0"/>
    2010-11-23 22:08:13,047 WARN [getArchivesFromTree] com.bea.cie.gpr.internal.feature.FeatureCatalogImpl - Unable to locate feature corresponding to feature reference: <xml-fragment feature="weblogic.server.modules.sca" feature-version="10.3.3.0"/>
    2010-11-23 22:08:13,048 WARN [getArchivesFromTree] com.bea.cie.gpr.internal.feature.FeatureCatalogImpl - Unable to locate feature corresponding to feature reference: <xml-fragment feature="weblogic.server.modules.dotnet" feature-version="10.3.3.0"/>
    2010-11-23 22:08:13,050 WARN [getArchivesFromTree] com.bea.cie.gpr.internal.feature.FeatureCatalogImpl - Unable to locate feature corresponding to feature reference: <xml-fragment feature="weblogic.server.modules.xquery" feature-version="10.3.3.0"/>
    2010-11-23 22:08:13,052 WARN [getArchivesFromTree] com.bea.cie.gpr.internal.feature.FeatureCatalogImpl - Unable to locate feature corresponding to feature reference: <xml-fragment feature="com.bea.cie.gpr" feature-version="3.0.1.0"/>
    2010-11-23 22:08:13,052 WARN [getArchivesFromTree] com.bea.cie.gpr.internal.feature.FeatureCatalogImpl - Unable to locate feature corresponding to feature reference: <xml-fragment feature="com.bea.cie.uninstall" feature-version="6.2.0.0"/>
    2010-11-23 22:08:13,053 WARN [getArchivesFromTree] com.bea.cie.gpr.internal.feature.FeatureCatalogImpl - Unable to locate feature corresponding to feature reference: <xml-fragment feature="com.bea.cie.uninstall.launch" feature-version="6.0.0.0"/>
    2010-11-23 22:08:13,054 WARN [getArchivesFromTree] com.bea.cie.gpr.internal.feature.FeatureCatalogImpl - Unable to locate feature corresponding to feature reference: <xml-fragment feature="com.bea.cie.uninstall.L10N" feature-version="6.2.0.0"/>
    2010-11-23 22:08:13,055 WARN [getArchivesFromTree] com.bea.cie.gpr.internal.feature.FeatureCatalogImpl - Unable to locate feature corresponding to feature reference: <xml-fragment feature="com.bea.cie.patch-client" feature-version="3.2.1.0"/>
    2010-11-23 22:08:13,066 WARN [getArchivesFromTree] com.bea.cie.gpr.internal.feature.FeatureCatalogImpl - Unable to locate feature corresponding to feature reference: <xml-fragment feature="com.bea.cie.patch-client.L10N" feature-version="3.2.0.0"/>
    2010-11-23 22:08:13,067 WARN [getArchivesFromTree] com.bea.cie.gpr.internal.feature.FeatureCatalogImpl - Unable to locate feature corresponding to feature reference: <xml-fragment feature="com.oracle.ocm" feature-version="1.0.0.0"/>
    2010-11-23 22:08:13,068 WARN [getArchivesFromTree] com.bea.cie.gpr.internal.feature.FeatureCatalogImpl - Unable to locate feature corresponding to feature reference: <xml-fragment feature="com.bea.cie.paf" feature-version="1.1.0.0"/>
    2010-11-23 22:08:13,069 WARN [getArchivesFromTree] com.bea.cie.gpr.internal.feature.FeatureCatalogImpl - Unable to locate feature corresponding to feature reference: <xml-fragment feature="com.bea.cie.clone" feature-version="1.1.0.0"/>
    2010-11-23 22:08:13,139 WARN [readCachedArchiveInfo] com.bea.plateng.wizard.installer.silent.tasks.ReadCachedArchiveInfoTask - Unable to read archive.bea from /var/folders/gQ/gQeTMB+nFpaLMIYi6zkEp++++TI/-Tmp-/
    2010-11-23 22:08:54,427 WARN [WizardController] com.bea.plateng.wizard.installer.gui.tasks.InstallSelectionSummaryTask - No JVMTargets selected for installation
    2010-11-23 22:09:17,095 WARN [Thread-5] com.bea.cie.gpr.internal.feature.FeatureCatalogImpl - Unable to locate feature corresponding to feature reference: <xml-fragment feature="weblogic.server.modules.pubsub" feature-version="10.3.3.0"/>
    2010-11-23 22:11:06,516 ERROR [stringSubst_gui] com.bea.plateng.wizard.WizardController - Uncaught Exception
    java.lang.IllegalArgumentException: http://java.sun.com/xml/jaxp/properties/schemaLanguage
         at org.apache.xerces.jaxp.DocumentBuilderFactoryImpl.setAttribute(DocumentBuilderFactoryImpl.java:118)
         at com.bea.plateng.common.util.StringsubsEngine.isValid(StringsubsEngine.java:1043)
         at com.bea.plateng.wizard.installer.helpers.StringsubsHelper.execute(StringsubsHelper.java:143)
         at com.bea.plateng.wizard.installer.helpers.StringsubsHelper.execute(StringsubsHelper.java:85)
         at com.bea.plateng.wizard.installer.helpers.StringsubsHelper.execute(StringsubsHelper.java:73)
         at com.bea.plateng.wizard.installer.gui.tasks.ProgressStringSubstTask.execute(ProgressStringSubstTask.java:150)
         at com.bea.plateng.wizard.gui.tasks.AbstractGUITask.run(AbstractGUITask.java:42)
         at java.lang.Thread.run(Thread.java:680)
    2010-11-23 22:12:01,325 WARN [WizardController] com.bea.plateng.wizard.installer.cleanup.tasks.CleanupShortcutsTask - No shortcuts to cleanup??
    2010-11-23 22:12:01,326 WARN [WizardController] com.bea.plateng.wizard.installer.cleanup.tasks.CleanupWinRegistryTask - No winregs to cleanup??
    Thanks in advance for some hints ...

    Official reply from Oracle via CS:
    "MacOSx 10.6.5 with Java 1.6.0_22 is not supported for JDeveloper version 11.1.1.2 and later. This has not been certified yet."

  • String substitution on Weblogic

    Hi experts.
    As you know, the WLS domain template provides the string substitution mechanism.
    (startscript.xml and stringsubs.xml)
    Here you should specify your entries that will be processed during the template applying.
    After being applied, these entries are "registered" in DOMAIN_HOME/init-info/ startscript.xml and startscript-unsub.xml
    Can these strsubs tasks be modified later?
    1) Is there any UI (or WLST functions) available for strsubs modification?
    Sure, I can edit xml files, but I think that it is not the convinient (and graceful) way to do it.
    2) As there is the startscript-unsub.xml file,
    does it mean that these string substitutions can be rolled back later?
    If yes - then how can it be done?
    Thanks

    There is currently no mechanism to perform string substitution after the config.xml has been created.

  • String Substitution in Preferences

    Hi,
    Can anyone please tell me what is the String Substitution in
    Run/Debug in Preferences menu? After I added a string substitution
    entry, how do I invoke it? Any examples of how to use it?
    I'm hoping it's something like shortcut keys that maps
    something like "pubf" to "public function". But seems like that's
    not it. I also tried to do mapping like that in the Keys setting in
    Preferences too, but couldn't get that to work either..
    thanks for any help,
    john

    String Substitution in Run/Debug in Preferences will not do
    what you want. String Substitution in that preference page is used
    to allow ${myvar} to be replaced with a different value in certain
    other dialog pages. It is documented here (but again, this is not
    what you want):
    http://help.eclipse.org/stable/index.jsp?topic=/org.eclipse.jdt.doc.user/reference/prefere nces/run-debug/ref-string_substitution.htm
    As for shortcut keys like "pubf" mapping to "public
    function", I don't know of a way to do that. One thing that does
    work, though, is that Alt+/ can be used as general-purpose word
    completion. What it does is it searches the current file for words
    that match what you have typed. So for example, if the current file
    already contains the word "public" somewhere else, then "pub"
    followed by Alt+/ will complete the word "public".
    But of course if the current file doesn't already contain the
    word "public" then that won't work. Alt+/ is really more useful for
    cases like this -- I have added a click handler,
    click="myNewClickHandler()", and then I want to implement that
    function, so I type
    public function myNew
    And then I type Alt+/ and it fills in the function
    name.

  • Urgent Help required! - Storing the XML as String instead as a file

    Hi,
    I need urgent help on this.
    I have an XML file. I have used org.w3c.dom to build dom and manipulate the XML file.
    I have updated the values for some of the nodes and I have deleted some of the unwanted nodes.
    I am able to save the output of the DOM as another XML file using
    either transform class or XMLSerializer with OutputFormatter class.
    But my requirement is to save the output of the DOM into a String instead of a file.
    When I save it in String, I need to have the following XML decalration and DOCTYPE declration also with it.
    <?xml version="1.0" encoding="UTF-8"?>
    <!DOCTYPE Test SYSTEM "Test.dtd">
    Can anyone pls help me in this??
    Thanks in Advance. Expecting some inpputs pls....!
    Regards,
    Gayathri.

    hi,
    i think this is what u want
        public static String getXmlString(Document d) {
          StringWriter strResponse = null;
          try {
             OutputFormat format  = new OutputFormat(d);
             strResponse = new StringWriter();
             XMLSerializer serial = new XMLSerializer( strResponse, format );
             serial.asDOMSerializer();
             serial.serialize(d.getDocumentElement());
          catch (Exception e) {
            System.out.println(e.toString());
          return strResponse.toString();
    }HTH
    vasanth-ct

  • Reading Each String From a text File

    Hello everyone...,
    I've a doubt in File...cos am not aware of File.....Could anyone
    plz tell me how do i read each String from a text file and store those Strings in each File...For example if a file contains "Java Tchnology forums, File handling in Java"...
    The output should be like this... Each file should contains each String....i.e..., Java-File1,Technology-File2...and so on....Plz anyone help me

    The Java� Tutorials > Essential Classes: Basic I/O

  • How to read and write a string into a txt.file

    Hi, I am now using BEA Workshop for Weblogic Platform version10. I am using J2EE is my programming language. The problem I encounter is as the above title; how to read and write a string into a txt.file with a specific root directory? Do you have any sample codes to reference?
    I hope someone can answer my question as soon as possible
    Thank you very much.

    Accessing the file system directly from a web app is a bad idea for several reasons. See http://weblogs.java.net/blog/simongbrown/archive/2003/10/file_access_in.html for a great discussion of the topic.
    On Weblogic there seems to be two ways to access files. First, use a File T3 connector from the console. Second, use java.net.URL with the file: protocol. The T3File object has been deprecated and suggests:
    Deprecated in WebLogic Server 6.1. Use java.net.URL.openConnection() instead.
    Edited by: m0smith on Mar 12, 2008 5:18 PM

  • How to write Strings in a text file with BufferedWriter

    I've got a Vector object full of Strings objects, I'm interested in wrinting these Strings in a text file with a BufferedWriter , I would apreciate some code, thank you

    http://java.sun.com/products/jdk/1.2/docs/api/java/io/BufferedWriter.html
    "PrintWriter out = new PrintWriter(new BufferedWriter((new FileWriter("foo.out")));"

  • Sender_interface_name in Variable Substitution in Receiver File Adapter CC

    Hi,
    as per this page : http://help.sap.com/saphelp_nw04/helpdata/en/bc/bb79d6061007419a081e58cbeaaf28/frameset.htm
    it says:
    Variable Substitution (Target Directory/File Name Scheme)
    If you set the Enable indicator, you can enter variables for the Target Directory and File Name Scheme. Enter the names of the variables and references in the table.
    ●      Enter each variable that you reference in the Target Directory and File Name Scheme fields without the surrounding percentage sign under Name of Variables in the table.
    The variables can refer to attributes of the message header or elements of the message payload.
    ○       If the variables are to refer to an attribute of the message header, add the prefix message: to the name of the variable under Reference. You can specify the following attributes of the message header:
    sender_party, sender_service, receiver_party, receiver_service, interface_name, interface_namespace, message_id, message_id_hex
    Can we not access sender_interface_name and sender_interface_namespace are not mentioned in above list of variables.
    Is it not possible to access sender_interface_name or sender_interface_namespace as variable substitute parameters from within Receiver File Adapter Communication channel.
    thanks.

    >Shabarish Vijayakumar wrote:
    >>the sender interface details will always remain a constant
    >>so you can hard code the value, isnt it?
    Yes, i can hardcode, thats not a bad idea, i need to create then 3 different Reciever File Communication Channel objects, as I am dealing with 3 scenarios for which sender system and sender interface is different.
    >Shabarish Vijayakumar wrote:
    >>if you look at the mapping runtime constants, those are also for the receiver since the sender interface will always remain constant for any particular CC.
    >>http://help.sap.com/saphelp_nw04/helpdata/en/b3/9a2aeb24dc4ab6b1855c99157529e4/content.htm
    yes in this link you provided i can see..
    INTERFACE     Interface
    INTERFACE_NAMESPACE     InterfaceNamespace
    SENDER_SERVICE     SenderService
    RECEIVER_SERVICE ReceiverService
    RECEIVER_NAME     ReceiverName
    RECEIVER_NAMESPACE     ReceiverNamespace
    it seems both INTERFACE (,INTERFACE_NAMESPACE) and RECEIVER_NAME(,RECEIVER_NAMESPACE) are present, may be one is for sender, and another is for receiver.. may be if i use dynamic configuration, possibly my issue would be addressed.. correct me if i am wrong.
    thanks.

  • Need some Help ( formating strings vs formatting input files)

    I have a program that reads in a text file and stores each line as a string. The input file has no delimiters and varying amounts of white space. The problem is, I am trying to display each line of the file the same way. Here is an example of what the string looks like when I read it in and then output the strings.
    (I am using the underline to represent white space just in this message post.)
    1.Fred Smith____GA_____23_______42______23.5_____3____5
    2.Jon Doe____SC___42_______3_______39.2_____6_____12
    Now here is is how I would like the output to look like.
    1.Fred Smith_______GA_______23_____42_____23.5_____3_____5
    2.Jon Doe__________SC_______42_____33_____39.2_____6_____12
    Any thoughts or insight on how to achieve this would be great. Thanks for the time.

    Hi, before I'd do anything more complicated, I'd replace some spaces with tabs and see if that does the trick.
    Cheers, HJK

  • How do i search for a string in a txt file using java??

    How do i search for a string in a txt file using java??
    could you please help thanks
    J

    Regular expressinos work just fine, especially when
    searching for patterns. But they seem to be impying
    it's a specific group of characters they're looking
    for, and indexOf() is much faster than a regex.If he's reading from a file, the I/O time will likely swamp any performance hit that regex introduces. I think contains() (or indexOf() if he's not on 5.0 yet) is preferable to regex just because it's simpler. (And in the case of contains(), the name makes for a very clear, direct mapping between your intent and the code that realizes it.)

  • Tell me Logic for search for duplicate words(or strings) in a large file.

    Search for duplicate words (or strings) in a text file containing one word per line. For each word that occurs more than once in the flat file output should be as follows
    <word> <number of occurrences> <line numbers in the file where the word occurs>
    For example, if the word Hello occurs thrice in a file at lines 100, 178 and 3456 the output should read
    Hello, 3, [100, 178, 3456]

    Incidentally i wrote similar code some days back. You need to do some modifications to get the exact output you want, but i hope it will be of some help.
    One more thing its written using JAVA5
    public class Test
         private static final String COLLECTIONS_TEXT = "C:\\Documents and Settings\\amrainder\\Desktop\\Collections.txt";
         public static void main(String[] args) throws IOException
              findDuplicateWords();
         private static void findDuplicateWords() throws IOException
              Collection<String> words = new LinkedHashSet<String>();
              File file = new File(COLLECTIONS_TEXT);
              StreamTokenizer streamTokenizer = new StreamTokenizer(new FileReader(file));
              int token = streamTokenizer.nextToken();
              while(token != StreamTokenizer.TT_EOF)
                   if(token == StreamTokenizer.TT_WORD)
                        words.add(streamTokenizer.sval);
                   token = streamTokenizer.nextToken();
              System.out.println(words);
    }Cheers,
    Amrainder

  • How can I parse an XML string, (not an XML file)?

    Hi,
    I am using Xerces2 Java Parser 2.4.0,
    I wanta parse an XML string, not an XML file, but
    in the Parser class there is only following methods:
    parse(InputSource source)
    parse(java.lang.String systemId)
    thanks

    hi
      InputSource is = new InputSource(new ByteArrayInputStream(xmlSrc.getBytes()));
      HTH
    vasanth-ct

  • Reading text file, Replace string, Write to new file....

    I'm kind a lost of on this problem. Using the BufferedReader class and BufferedWriter class, develop an application that reads lines of text from a file. Replace any occurrence of the word *?the?* with *?JAVAJAVA?* and change all characters to upper case before writing each line to a different text file named outfile.txt. Finally, have your application use the appropriate method on the File class to return the absolute path of the outfile.txt file and output the path to the screen.
    * Created December 10, 2008
    * @author Fausto Rivera
    * Colorado Technical University - Online Campus
    * IT271-0804B-02 Intermediate Object Oriented Programming II
    * Phase 2 IP
    * Instructor: Cheryl B Frederick
    import java.io.File;
    import java.io.BufferedReader;
    import java.io.BufferedWriter;
    import java.io.FileNotFoundException;
    import java.io.FileReader;
    import java.io.FileWriter;
    import java.io.IOException;
    public class FRiveraReader {
          public static void main(String[] args) {
          // instantiated a new application object to initialize the application
          FRiveraReader application = new FRiveraReader();}
    //      application.getReadfr();  // call to openFile method
    //      application.doWritefr(); // call to readRecords method
    //      application.closeFile();  // call to closeFile method
    public FRiveraReader(){}
      public void getReadfr (String friveraInfile, String fr []){
       int i;
       File fileName = makeAbsoluteFilename(friveraInfile);
       try{
        BufferedReader reader = new BufferedReader(new FileReader(fileName));
        String line = reader.readLine();
         i=0;
          while (line != null) {
           fr[i] =line;
           line = reader.readLine();
        i++;
      reader.close();
    catch(IOException e) {
    System.out.println("Error with reading file:" + friveraInfile);
    }//end of getOrder method
    public void doWritefr(String friveraOutfile, String fw[]){//String name of file, String array to be written
    int i;
    File fileNameout = makeAbsoluteFilename(friveraOutfile);
    try {
    BufferedWriter writer = new BufferedWriter(new FileWriter (fileNameout));
      i=0;
      while (fw[i] != null) {
       writer.write(fw[i] + "%n"); //need delimiters between data in file;also, reader reads a line
       i++;
      writer.close();
    catch(FileNotFoundException e) {
    System.out.println("File not found");
    catch(IOException e) {
    System.out.println("Error with reading file:" + friveraOutfile);
    }//end of getOrder method
    private File makeAbsoluteFilename(String friveraOutfile)//these 2 classes used to resolve file name
            File file = new File(friveraOutfile);
            if(!file.isAbsolute()) {
                file = new File(friveraOutfile);
            return file;

    I have modified my code as far as being able to create a text file, write to string, and change to upper case. Now, how can I connected input to the output stream and then replace all the instances of the string "the" for the string "JAVAJAVA"? When the file is created, it goes into a loop writing the following:
    nJAVA.IO.BUFFEREDWRITER@19821F%nJAVA.IO.BUFFEREDWRITER@19821F%nJAVA.IO.BUFFEREDWRITER@19821F%nJAVA.IO.BUFFEREDWRITER@19821F%nJAVA.IO.BUFFEREDWRITER@19821F%nJAVA.IO.BUFFEREDWRITER@19821F%
    Here is my modified code
    import java.io.File;
    import java.io.BufferedReader;
    import java.io.BufferedWriter;
    import java.io.FileNotFoundException;
    import java.io.FileReader;
    import java.io.FileWriter;
    import java.io.IOException;
    public class FRiveraReader {
    public FRiveraReader() {}
    private static final String inFile = "C:\\Documents and Settings\\Fausto Rivera\\My Documents\\NetBeansProjects\\Rivera_F_IT271_0804B_02_PH2_IP\\friverainfile.txt";//the path name of your file
      public void myReadfr (){
       try {
        BufferedReader reader = new BufferedReader(new FileReader(inFile));
        //String "JAVAJAVA" = String "the";
        System.out.println(inFile);
        String line = reader.readLine();
          while (reader != null) {
           line = reader.readLine();
      reader.close();
    catch(IOException e) {
    System.out.println("Error with reading file:" + inFile);
    }//end of myReadfr method
    public void myWritefr(){//String name of file, String array to be written
    File outFile = new File ("C:\\Documents and Settings\\Fausto Rivera\\My Documents\\NetBeansProjects\\Rivera_F_IT271_0804B_02_PH2_IP\\myoutFile.txt");
    try {
    BufferedWriter writer = new BufferedWriter(new FileWriter (outFile));
    String newline = writer.toString() .toUpperCase();
      while (writer != null) {
       writer.write(newline + "%n"); //need delimiters between data in file;also, reader reads a line
      writer.close();
    catch(FileNotFoundException e) {
    System.out.println("File not found");
    catch(IOException e) {
    System.out.println("Error writing file:" + outFile);
    }//end of getOrder method
    private File makeAbsoluteFilename(String myoutFile)//these 2 classes used to resolve file name
            File file = new File(myoutFile);
            if(!file.isAbsolute()) {
                file = new File(myoutFile);
            return file;
      }Edited by: FRiveraJr on Dec 17, 2008 12:10 PM

  • How do I save a string to a CSV file using applescript?

    Hi,
    I have an applescript that returns a string in the form:
    Value1,Value2,Value3,Value4
    Value5,Value6,Value7,Value8
    Value9,Value10,Value11,Value12
    Value13,Value14,Value15,Value16   etc.
    I would like to be able to save this string as a CSV file on my desktop but I'm not sure how to do this.
    Could someone help me out with this?
    Thanks,
    Nick

    sorry, I didn't read carefully.  this is slightly better:
    set theText to "some delimited text you already have..."
    set filePath to (path to desktop as text) & "file name.csv"
    set fp to open for access filePath with write permission
    write theText to fp
    close access fp

Maybe you are looking for

  • In Dreamweaver MySites[New Site] menu option , if I had a hosting JSP/PHP what I must declare the hosting JSP or PHP ?

    In Dreamweaver MySites[New Site] menu option , if I had a hosting JSP/PHP what I must declare the hosting JSP or PHP ?

  • I keep loosing internet access

    Even though my data is selected , it keeps dropping every few minutes from 1x to 4g then dropped again for 5-10 min. It is soooo slow even when it says 4g it takes forever to load ...ive been fighting the internter for 2 hours just to get to ask this

  • EMT 252, 250 and nonlin Space Designer IRs

    Just got the latest Acousticas library. EMT252XL. It's a whopper with about 2000 irs, incl. the 252 with 250 and nonlin programs. I really like the detail put into this one. The frequency multipliers are there as well, making it a breeze controlling

  • Find me/Follow me features in Skype for business/S...

    Does Skype for Business support find me / follow me features? I recently discovered that if you associate a Business Account with a SIP profile, that account can no longer log in to the Skype App anywhere.  I was looking for the ability to have a cal

  • ICal blocks upon opening, Help!!!

    On my IMac I'm running O/S 10.6.2, Safari 4.0.4. ICal was configured to open upon boot-up. Recently, ICal has been opening and immediately the multi-colored little spinning disc replaces the mouse pointer and I cannot proceed with any type of action