How to include file-separator in fileName?

I'm retrieving the file name from a function and that function returns me the string and now I can't change this.
String fileName="C:\jdk1.2\hello.java"
Now next with this file Name I'm making a file object
File f=new File(fileName);
FileInputStream in=new FileInputStream(f);
but this gives me error..that it doesn't found the specified the file given...
so this means I must give the separator as C:\\jdk1.2\hello.java
but I can't change the value returned to me by the function...
So this means that I have to make a function replace which converts '\' to '\\'
String newfileName=replace(fileName);
so please can anybody tell me how to write this funcion? Actually I can't use replace fn. of String class, as it says that '\' is invalid escape character...u try it and compile the result and tell me
thanx in advance for the favourable response

mmmmmhhh... hi!
I don't whant to be mean but I did't understand what's the problem at all? Are you trying to implement a new method to replace the '\' with '\\' in Strings????. Let me guess:
private static String replace(String input) {
String output = null;
//.. do something;
return output;
But beware: you cannot call this method as, say,
String path = replace("C:\My Documents\User\texts\file.dat");
to get "C:\\My Documents\\User\\texts\\file.dat"... First the argument is invalid, and second you're missing the fact that what you want is to preprocess the text of the java SOURCE FILE, not a String object to handle like ***text in you source file***...
Just write your strings like "C:\\My Documents\\User\\Home\\docs.txt" or "C:/My Documents/User/Home/docs.txt" (I personally use the later)
But please see what's the problem:
"C:\My Documents\User\Home\docs.txt"
is not even a String!!!
If you do
System.out.println("C:\\My Documents\\User\\Home\\docs.txt");
System.out.println("C:/My Documents/User/Home/docs.txt");
System.out.println("C:\\\\My Documents\\\\User\\\\Home\\\\docs.txt");
the output will be
C:\My Documents\User\Home\docs.txt
C:/My Documents/User/Home/docs.txt
C:\\My Documents\\User\\Home\\docs.txt
... hope I didn't misunderstand the question nor did I oversimplify the issue, I just guess you got lost with the concept...

Similar Messages

  • How to include files in isolated storage

    I am developing an app that has some static files that I need to access.
    I would like to be able to include those files in my VS project and have them loaded to Isolated Storage when the app is installed on the phone.
    I am accessing the file with IsolatedStorage calls, such as:
    if(myIsolatedStorage.FileExists("cb.xml"))
    I have added a file to my project and have set the properties for the file to say it is "content". However, it does not show up in local storage.
    How do I do this?

    Does anyone have links to some sample code to do this?
    Thanks!
    Found these two:
    http://msdn.microsoft.com/en-us/library/ms596994(v=vs.95).aspx
    https://code.msdn.microsoft.com/windowsapps/Accessing-files-sent-with-4b429e23

  • How to export file with original filename number suffix, but with more digits

    Is there a way to keep the original filename number suffix, but change the formatting of the number, adding leading zeros for instance?
    When I import photos from my camera I like to rename them, and give them sequential numbers, e.g. "2015-01 Hamburg 1.cr2", "2015-01 Hamburg 2.cr2", "2015-01 Hamburg 10.cr2", .. "2015-01 Hamburg 134.cr2", and so on.
    Normally when I export photos I like to keep the file names exacly as I imported them (except the extension) e.g. 2015-01 Hamburg 1.jpg, "2015-01 Hamburg 2.jpg", .. "2015-01 Hamburg 10.jpg", .. "2015-01 Hamburg 134.jpg".
    But sometimes I would like to export them with leading zeros, typically when adding photos to a web site or blog where there are sort mechanisms that only support simple sort algorithms based on file names, meaning the sort order of my photos with their original file names would become "2015-01 Hamburg 1.jpg, "2015-01 Hamburg 10.jpg", .. "2015-01 Hamburg 134.jpg", "2015-01 Hamburg 2.jpg".
    So I would like the file names to be "2015-01 Hamburg 001.jpg", "2015-01 Hamburg 002.jpg", "2015-01 Hamburg 010.jpg", "2015-01 Hamburg 134.jpg".
    By keeping the original file number suffix I can easily go back to the original file whenever I need to, and the sort order would work even with simple sorting.
    The export Filename Template Editor gives quite advanced support for numbering files when exporting, see attached screenshot. There's support for exporting files with custom file names, and adding sequence, total and image number with padding (up to 9999/####). But those add new numbers, they do not consider the original filename number suffix. If I use the "Image # (001)" for instance, my example above would export as "2015-01 Hamburg 001.jpg", "2015-01 Hamburg 002.jpg", "2015-01 Hamburg 003.jpg", "2015-01 Hamburg 004.jpg", if those were the four photos I wanted to export, making it hard for me to trace them back to the original photo.
    I have found no way of adding such padding on the original file number.
    Does anyone know if this is possible or have suggestions for a workaround?
    It shouldn't be too hard for Adobe to support this I'd imagine.
    export pattern rename files  file_number filename_template_editor

    I do not know if you can do what you explained above, but there is a workaround to this (and a way to avoid having to do it in the future):
    In the Library module, make sure your images are sorted by Capture Date (this will put them in the right order, even with suffixes like 1, 13, etc.)
    Select all images, and then Rename them, using a Custom text followed by a Sequence number. The Custom text in this case should be the original name (such as, 2015-01 Hamburg, as in your example). Make sure the Sequence number is formatted with enough zeroes to include all the numbers in your images.
    In the future, when you rename images during Import, make sure you select the Sequence number format that will include all the needed zeroes, so you don't have to go through this again.

  • AI 10 How to get File- Separation Setup's color plate options using SDK?

    Hi All,
    Im using Microsoft VC++6.0 & Illustrator 10 SDK.
    How can i get access to "File->Seperation setup " menu of the document using SDK.Which header file should i use?
    Actually i need to get the color plates which are on/off inside the separation setup dialog.
    Any sample code please.
    Thanks in advance
    Regards
    myRiaz

    It sounds like you need to figure out which part of the API deals with colour separation. It could be AIDocument.h or it could be AIColor.h. I'm afraid you'll just have to check the headers until you find something that looks like you want. You could also try searching the API for a piece of text that you'd expect to find associated with the values you're trying to pull -- that might point you in the right direction.

  • How to include file extensions in contacts?

    When printing contact sheets from the Print module I don't manage to have the file name inclusive of file extension under each thumbnail (e.g. Maria.jpg); so far I only managed to have the file name without the extension (e.g. Maria). Any idea how to do it?

    F-
    <br />
    <br />I doubt it's impossible, but why would you choose to do this? I we know, perhaps another method may suffice.
    <br />
    <br />
    <span style="color: rgb(102, 0, 204);"></span>
    <font br="" /></font> color="#600000" size="2"&gt;~~ John McWilliams
    <br />
    <br />
    <br />
    <br />MacBookPro 2 Ghz Intel Core Duo, G-5 Dual 1.8; Canon DSLRs

  • How to include file path in footer

    I need to add file paths to a pdf I have created.  Does anyone know how?  I know that there are JavaScript ways, but I am not even sure what a Java Script is.
    Thanks for any insight!

    If you do not know how to use JavaScript, there is this option: Custom-made Adobe Scripts: Acrobat/Reader -- Advanced Add Header/Footer Text (but it's not free).

  • How to find files with duplicate filenames

    I am trying to find all the files I have on a particular HD that have the same file names. They probably aren't duplicate files but just have the same name.
    Basically, my volume has 850 GB of RAW images. I have recently adopted a new name scheme in order to improve the organisation of the files. The new name is based on SFAYYMMDDXXXX (where SFA identifies it is my image. YYMMDD is the date it was created. XXXX is a 4 digit counter starting at 0001 for each day).
    My slight concern comes from the fact that the images are in different folders. I used to store images according to the shoot type. So it may have been possible that some file names have been used more than once.
    While this is not a massive problem at the moment, it kind of defeats one of the reasons that I changed the naming scheme... To have a unique name for every file.
    What I would like to do is find a quick way of scanning the whole HD and identifying whether there are any files sharing the same file name even if they are in different folders.
    Any ideas?

    Yes snapper - download either FindFile at http://www.versiontracker.com/dyn/moreinfo/macosx/10906315
    or EasyFind at http://www.versiontracker.com/dyn/moreinfo/macosx/8707
    either of these will search your entire hard drive (which Spotlight won't unless you fiddle with it).
    when they've finished their search, simply click the title of the "name" column and all the ones with the same name will be grouped.
    You can then use the EasyFind or FindFile menu to locate the actual files, and decide what to do with them.

  • How to change the filename in @include file?

    I want to do a checking before deciding to include which file,
    for example,
    <%
    if(isValid){
    %>
    <%@ include file="abc.jsp" %>
    <%
    else{ %>
    <%@ include file="def.jsp" %>
    <% } %>but the code above doesnt work in my JSPs
    any idea how to solve this?
    thanks
    Desmond

    Am i clear?? pls correct me if i am wrong..You are wrong.
    The include directive is being used here, which is a compile time include, not a runtime include. Both includes will be performed before the resulting servlet is compiled.
    If they have a conflict between them (either by not nesting them in their own { scope } or using <%! declarations %>) then the generated servlet will fail to compile.
    So if you had the following:
    abc.jsp:
    Hello from ABC!
    <% String myVar = "ABC"; %>def.jsp:
    Hello from DEF!
    <%  String myVar = "DEF";  %>And the page as mentioned in the original post, you would end up with a Servlet something like this:
    if (isValid){
       out.println("Hello from ABC!");
        String myVar = "ABC";
    else{
       out.println("Hello from DEF!");
      String myVar = "DEF";
    }This example would compile because of the presence of the braces.
    However removing the braces or using a <%! declaration %> would probably screw things up with a compile error.
    The %Include directive is like a copy/paste into a JSP before you compile it.
    The <jsp:include> is evaluated at runtime and copies in the result of executing the page.
    The difference is quite subtle, but very important.
    Cheers,
    evnafets

  • How to include a .class file in a jsp page

    hi everyone,
    i know the syntax as:
    <%@ include file = "filename.class" %>
    then at run time the server could not find the class file
    if i use,
    <%@ page import = "FileName.class" %>
    then also the same problem persists
    & if i use
    <jsp:include page = "Relative address"/>
    the problem still remains as it is...
    please help me out...i am working on developing an EJB application in which client interacts with server's Stateful session bean through a jsp page...it is necessary for me to include the home interface class file in my jsp page.
    P.S. do not suggest me to include the class file in a package & then use
    <%@ page import = "packageName.ClassFileName" %>
    i
    Edited by: Ankit_JIITU on 6 Jul, 2008 1:55 AM

    Ankit_JIITU wrote:
    i have already included the remote interface class file by <%@ page import = "University.RemoteInterfaceName" %>in my jsp page ...
    if i try to make a new package called test & then include my home interface in that package...i need to import University.*to generate the class file of my home interface ; but the class file generation is not taking place as i am getting the error..
    "package University does not exist".How can i overcome this problem. The package University, which you are trying to import, must be in the classpath. If you removed it then you will have to add it back.
    i have tried my best..but tell me if there's any possible way of including a class file in the jsp page without involving a package.No, there isn't.
    If not,then pls help me to generate the class file of my home interface within a package called test.Read the New To Java Tutorial and understand how packages work.
    >
    i am assuming that u have a deep knowledge of developing EJB applications.

  • How to get field separator in flat file using GUI_DOWNLOAD function

    hi,
    how to get field separator in flat file using GUI_DOWNLOAD function.
                                    thanking you.

    Hi,
      Use WRITE_FIELD_SEPARATOR = 'X'.
      Check this sample code
    REPORT  z_file_download.
    DATA: w_name(90) TYPE c.
    DATA:
      BEGIN OF fs_flight,
        carrid   LIKE sflight-carrid,
        connid   LIKE sflight-connid,
        fldate   LIKE sflight-fldate,
        price    LIKE sflight-price,
        currency LIKE sflight-currency,
      END OF fs_flight.
    DATA:
      BEGIN OF fs_head,
        carrid(10) TYPE c,
        connid(10) TYPE c,
        fldate(10) TYPE c,
        price(10) TYPE c,
        curr(10) TYPE c,
      END OF fs_head.
    DATA:
      t_head LIKE
       TABLE OF
             fs_head.
    DATA:
      t_flight LIKE
         TABLE OF
               fs_flight.
    fs_head-carrid = 'CARRID'.
    fs_head-connid = 'CONNID'.
    fs_head-fldate = 'FLDATE'.
    fs_head-price  = 'PRICE'.
    fs_head-curr   = 'CURRENCY'.
    APPEND fs_head TO t_head.
    SELECT-OPTIONS:
      s_carrid FOR fs_flight-carrid.
    START-OF-SELECTION.
      SELECT carrid
             connid
             fldate
             price
             currency
        FROM sflight
        INTO TABLE t_flight
       WHERE carrid IN s_carrid.
    CALL FUNCTION 'GUI_DOWNLOAD'
      EXPORTING
    *   BIN_FILESIZE                  =
        filename                      = 'D:\flight.xls'
       FILETYPE                      = 'ASC'
    *   APPEND                        = ' '
        WRITE_FIELD_SEPARATOR         = 'X'
    *   HEADER                        = '00'
    *   TRUNC_TRAILING_BLANKS         = ' '
    *   WRITE_LF                      = 'X'
    *   COL_SELECT                    = ' '
    *   COL_SELECT_MASK               = ' '
    *   DAT_MODE                      = ' '
    *   CONFIRM_OVERWRITE             = ' '
    *   NO_AUTH_CHECK                 = ' '
    *   CODEPAGE                      = ' '
    *   IGNORE_CERR                   = ABAP_TRUE
    *   REPLACEMENT                   = '#'
    *   WRITE_BOM                     = ' '
    * IMPORTING
    *   FILELENGTH                    =
      tables
        data_tab                      = t_head
    EXCEPTIONS
       FILE_WRITE_ERROR              = 1
       NO_BATCH                      = 2
       GUI_REFUSE_FILETRANSFER       = 3
       INVALID_TYPE                  = 4
       NO_AUTHORITY                  = 5
       UNKNOWN_ERROR                 = 6
       HEADER_NOT_ALLOWED            = 7
       SEPARATOR_NOT_ALLOWED         = 8
       FILESIZE_NOT_ALLOWED          = 9
       HEADER_TOO_LONG               = 10
       DP_ERROR_CREATE               = 11
       DP_ERROR_SEND                 = 12
       DP_ERROR_WRITE                = 13
       UNKNOWN_DP_ERROR              = 14
       ACCESS_DENIED                 = 15
       DP_OUT_OF_MEMORY              = 16
       DISK_FULL                     = 17
       DP_TIMEOUT                    = 18
       FILE_NOT_FOUND                = 19
       DATAPROVIDER_EXCEPTION        = 20
       CONTROL_FLUSH_ERROR           = 21
       OTHERS                        = 22
    IF sy-subrc <> 0.
    * MESSAGE ID SY-MSGID TYPE SY-MSGTY NUMBER SY-MSGNO
    *         WITH SY-MSGV1 SY-MSGV2 SY-MSGV3 SY-MSGV4.
    ENDIF.
      CALL FUNCTION 'GUI_DOWNLOAD'
        EXPORTING
          filename                = 'D:\flight.xls'
          filetype                = 'ASC'
          append                  = 'X'
          write_field_separator   = 'X'
        TABLES
          data_tab                = t_flight
        EXCEPTIONS
          file_write_error        = 1
          no_batch                = 2
          gui_refuse_filetransfer = 3
          invalid_type            = 4
          no_authority            = 5
          unknown_error           = 6
          header_not_allowed      = 7
          separator_not_allowed   = 8
          filesize_not_allowed    = 9
          header_too_long         = 10
          dp_error_create         = 11
          dp_error_send           = 12
          dp_error_write          = 13
          unknown_dp_error        = 14
          access_denied           = 15
          dp_out_of_memory        = 16
          disk_full               = 17
          dp_timeout              = 18
          file_not_found          = 19
          dataprovider_exception  = 20
          control_flush_error     = 21
          OTHERS                  = 22.
      IF sy-subrc EQ 0.
        MESSAGE 'Download successful' TYPE 'I'.
      ENDIF.
      IF sy-subrc <> 0.
    *  MESSAGE ID SY-MSGID TYPE SY-MSGTY NUMBER SY-MSGNO
    *         WITH SY-MSGV1 SY-MSGV2 SY-MSGV3 SY-MSGV4.
      ENDIF.

  • How to include a html file in jsp

    hi all
    I have a question about including a html in jsp.
    here's the sample of my jsp file:
    <%
    String filename = "helloworld.html";
    %>
    <%@ include file="helloworld.html" %>
    how will you go about doing it so that the included file depends on the variable "filename"? I've tried doing the following but I got an error:
    <%@ include file=filename %>
    Thank you very much :)

    try this:-
    <%
    String filename = "helloworld.html";
    %>
    <jsp:include page='<%= filename %>' />
    This should work.

  • How to include header files with different extensions

    Hi,
    When i include a header file with extension .ch (myincludefile.ch), the compiler gives error messages but when i change the extension to .h, the problem disappears.
    Can anyone help me getting rid of this problem?
    For example, for the line below, I get a warning such as, "attempt to redefine MY_CONST without #undef". Remember when i change the extension to .h, the problem disappears.
    #define MY_CONST 500 /* Constant */
    Thank you very much

    I don't see how the name of the file could cause or prevent error messages, except when template declarations are involved. So let's assume for now that the file has a template declaration.
    The Templates chapter of the C++ Users Guide explains about including or separating template declarations and their definitions.
    If you have only a template declaration in a file and the compiler needs the definition, it will look for another file with the same base name and include it automatically. For example, if you have files foo.h and foo.cc, and foo.h has a template declaration, the compiler will include foo.cc automatically, even if you didn't intend for that to happen. You can wind up with multiple delcaration errors that way.
    When looking for a file containing template definitions, the compile will not include a .h file, so as not to create recursive inclusion. If changing the file name to .h causes your problem to disappear, it seems like an unwanted automatic inclusion is the problem.
    You can try two things to find out:
    1. Compile with the -H option. The compiler will output an indented list of all included files. See if you are getting a file you didn't intend, or the same file twice.
    2. Compile with option -template=no%extdef. It disables the automatic search for template definitions.
    If you find an unintended included file this way, you will probably have to change the names or organizaiton of some of the files. Our implementation of the C++ standard library depends on NOT using the -template=no%extdef option, which might mean you can't use that option.

  • How to include help file in application

    Hello,
    i developed an application using java swing. i need to include help file in my application. How to include it?
    Thanks,
    Sri

    Hi Sri,
    Use Java Help....
    There is some thing called as Help set. In a button action listener u have to call that.
    HelpSet helpSet = getHelpSet("path");
    HelpBroker helpBroker = helpSet.createHelpBroker();
    CSH.setHelpIDString (jButton,"filename");
    jButton.addActionListener(new CSH.DisplayHelpFromSource(helpBroker));
    Regards,
    Kumar

  • How to include a static file.... Please help..

    Hi guys..
    i am going crazy here, so please help.... is it possible to use <jsp:include page="headlines.html" flush="true"/> to serve a static file( headlines.html) which is in say tomcat_home\bin.. also, i wonder why the following code creates a headline file in the bin folder in the first place.. i thought, it should create headlines.html in the same folder as this class...i am a newbie as you can see...thanks in advance
    package beanpackage;
    import javax.xml.transform.stream.StreamSource;
    import javax.xml.transform.stream.StreamResult;
    import java.io.FileOutputStream;
    import javax.xml.transform.TransformerFactory;
    import javax.xml.transform.Transformer;
    import java.io.File;
    public class RSSProcessor {
    public RSSProcessor(){ }
    String _RSSFile;
    public String getRSSFile(){
    return _RSSFile;
    public void setRSSFile(String fileName){
    try {
    StreamSource source = new StreamSource(fileName);
    StreamSource finalStyle = new StreamSource("final.xsl");
    String outputURL = "headlines.html";
    StreamResult result = new StreamResult(new
    FileOutputStream(outputURL));
    TransformerFactory transFactory = TransformerFactory.newInstance();
    Transformer transformer = transFactory.newTransformer(finalStyle);
    transformer.transform(source, result);
    } catch (Exception e) {
    e.printStackTrace();
    }

    I am just about there thanks to you stibrian..
    as you know that i am using a bean and a jsp to transform the rss feed.. following your direction i used String filePath = getServletContext().getRealPath etc. in my JSP and i am getting my headlines.html in the ROOT folder every time i reload the JSP.. thats great ! but my <jsp:include page="headlines.html" flush="true"/> is still not working(i tried every possible combination).. is there any thing wrong? I will post my new code below and i hope that i would not bother you again (on this:-).. thanks a lot.. also, i will add some dukes to this question, as a thank you..
    package beanpackage;
    import javax.servlet.*;
    import javax.servlet.http.*;
    import javax.xml.transform.stream.StreamSource;
    import javax.xml.transform.stream.StreamResult;
    import java.io.FileOutputStream;
    import javax.xml.transform.TransformerFactory;
    import javax.xml.transform.Transformer;
    import java.io.File;
    import java.io.*;
    public class RSSProcessor {
    public RSSProcessor(){ }
    String _RSSFile;
    public String getRSSFile(){
    return _RSSFile;
    public void setRSSFile(String fileName, String outputURL){
    try {
    StreamSource source = new StreamSource(fileName);
    StreamSource finalStyle = new StreamSource("final.xsl");
    //String outputURL = getServletContext().getRealPath("WEB-INF" + File.separator + "headlines.html");
         //String outputURL = "headlines.html";
    StreamResult result = new StreamResult(new
    FileOutputStream(outputURL));
    TransformerFactory transFactory = TransformerFactory.newInstance();
    Transformer transformer = transFactory.newTransformer(finalStyle);
    transformer.transform(source, result);
    } catch (Exception e) {
    e.printStackTrace();
    <!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN">
    <jsp:useBean id="rssBean" scope="request" class="beanpackage.RSSProcessor">
    <%@ page import="java.io.File"%>
    <%String outputURL = getServletContext().getRealPath(File.separator + "headlines.html");%>
    <%
    rssBean.setRSSFile("http://www.rediff.com/rss/inrss.xml", outputURL);
    %>
    </jsp:useBean>
    <html>
    <head>
    <title>Syndicated Feeds</title>
    </head>
    <body>
    <jsp:include page="headlines.html" flush="true"/>
    </body>
    </html>

  • How to include the file name as an XML field

    Hi,
    I'm using a file adapter for process a flat file and convert it into an XML. Does anybody knows how to include the file name into an XML field.
    Ex.
    I process the file named <b>XXIMN21022007.txt</b> and I need an XML like:
    <MT_FILE>
    <field1></field1>
    <field2></field2>
    <field3></field3>
    <filename><b>XXIMN21022007.txt</b></filename>
    </MT_FILE>
    Regards
    Gonzalo

    Just go for dynamic configuration.
    Check the sender file adapter to write the filename in the header (as explained in Michal's blog) and then read that header in some mapping.
    U can use that even in simple message mappings.
    http://help.sap.com/saphelp_nw2004s/helpdata/en/43/03612cdecc6e76e10000000a422035/frameset.htm
    Your code for the filename tag would be something like:
    <i>DynamicConfiguration conf = (DynamicConfiguration) container
        .getTransformationParameters()
        .get(StreamTransformationConstants.DYNAMIC_CONFIGURATION);
    DynamicConfigurationKey key = DynamicConfigurationKey.create(
        “http://sap.com/xi/XI/System/File”,
        “FileName”);
    return conf.get(key);</i>
    Regards,
    Henrique.

Maybe you are looking for

  • Recording sound from DVD and CD play

    I just bought a Zen V Plus. Could someone please tell me how to record sound from a DVD and/or CD to my MP3? Thank you!

  • Middle Eastern type/Hebrew not working in CC 2014

    Hebrew used to work for me in CC. Now in cc 2014 it's not. I have Hebrew installed in windows, middle eastern type engine selected, and middle eastern text options available. When right-to-left is selected, it still types left-to-right. I've tried pa

  • Problems with 'Order Prints' from Aperture 2.1.3 Mystery borders

    *Some background:* I've been using Aperture for about 3 months now, importing most of my iPhoto library into the program. I have only recently started shooting in RAW format, most of my photos image files are in JPG format. In the past, I've had no p

  • Something unexpected went wrong with this url...class not registered

    Cannot open links in Outlook 2013 with default browser set to FireFox (26.0). If I set Internet Exploder as the default, I can open links in Outlook 2013. Windows 8 x64 Thanks Stuart

  • ODI integration with SAP HRMS

    Hi, We got a requirement to fetch the data from SAP HRMS and store in SQL Server. I have knowledge in ODI. But I don't have any idea about SAP. In Topology Manager we have technologies like SAP, SAP Java Connector. Under which technology do we need t