File.length()

I have the following questions:
when I read File.length() of bytes of data, Does the data consist of end of file charactor?
thanks
mark ma

atleast, on my windows 2000 machine it doesn't...
import java.io.*;
public class Test {
  public static void main(String args[]) {
    try {
      String s = "This is a test";
      System.out.println(s.getBytes().length);
      PrintWriter pw = new PrintWriter(new FileOutputStream("test.txt"));
      pw.print(s);
      pw.close();
      File f = new File("test.txt");
      System.out.println(f.length());
    catch (Exception e) {
      e.printStackTrace();
}

Similar Messages

  • Application server file length

    Hi,
    I am doing outbound proxy, where it si executed successfully and the file was placed in the appropriate location, but the file length is more than 255 characters , so i am unable to look into my whole file structure. My source file and target file structre is different some client related header is present in the target file. When i cheked in the sxmb_moni also my target message is not appearing. I have checked under inbound message flag and receiver grouping flag in both payloads it is showing my source structure. in response flag there is no payload folder. So finally iam unable to look at file whole file structure. Can any body suggest me what to do to look at my whole file structure. Even i try to download the file from application server even then also i am getting only till 255 characters of length. Kindly suggest some solution .
    Venkat

    Hi,
    I am doing outbound proxy, where it si executed successfully and the file was placed in the appropriate location, but the file length is more than 255 characters , so i am unable to look into my whole file structure. My source file and target file structre is different some client related header is present in the target file. When i cheked in the sxmb_moni also my target message is not appearing. I have checked under inbound message flag and receiver grouping flag in both payloads it is showing my source structure. in response flag there is no payload folder. So finally iam unable to look at file whole file structure. Can any body suggest me what to do to look at my whole file structure. Even i try to download the file from application server even then also i am getting only till 255 characters of length. Kindly suggest some solution .
    Venkat

  • Problem with file length in jsp it is working in IE, not workig Firefox

    Hi,
    I'm upload a file from the browser. i'm calculating the length i'm not getting the length of the file.
    The below shown code is working perfectly in IE and not working in Firefox.
    FileUpload.html
    <DOCTYPE>
    <HTML>
    <HEAD>
    <TITLE>Retailmint Jobs - Registration Form</TITLE>
    </HEAD>
    <BODY>
    <form>
    <table>
    <tr><td>Upload Resume :</td>
    <td> <input>
       </td>
    </tr>
    </table>
    <input>
    </p>
    <p>  </p>
    </form>
    </BODY>
    </HTML>
    FileUploadSubmit.jsp
    <page>
    <page>
    <page>
    <html>
    <head><title>Retailmint- Submission</title></head>
    <body>
    <FileInputStream>
    </body>
    </html>
    I find an error in firefox browser is not taking the fully qualified path
    i.e: C:\Documents and Settings\Administrator\Desktop\if.doc
    In firefox it is taking if.doc only.
    please tell me the solution.
    Regards
    venkat

    Sorry for that
    here is the code:
    FileUpload.html
    <HTML>
    <HEAD>
    <TITLE>Retailmint Jobs - Registration Form</TITLE>
    <script language="Javascript" src="FileRead.js">
    </script>
    </HEAD>
    <BODY>
    <form name='subregiform' method="get" action ="FileuploadSubmit.jsp" >
    <table width="566" border="0" cellspacing="0" cellpadding="0">
    <tr><td width="197"align="right">Upload Resume :</td>
    <td width="369"> <input type="file" name="file" value ="" onchange ="javascript:fopen('file');"><br>
       </td>
    </tr>     
    </table><br>
    <input type="submit" name="submit" value="Submit">
    </strong></p>
    <p>  </p>
    </form>
    </BODY>
    </HTML>
    FileUploadSubmit.jsp
    <%@ page import="java.text.*"%>
    <%@ page import="java.sql.*" %>
    <%@ page import="java.util.*" %>
    <%@ page import="java.io.*" %>
    <jsp:useBean id="DBase" class="dbconnection.DBconnection" scope="session" />
    <html>
    <head><title>Retailmint- Submission</title>
    </head>
    <body bgcolor="#e0e0e0">
    <%
    FileInputStream fis = new FileInputStream(request.getParameter("file"));
    len = (int)file.length();
                   System.out.println("length"+len);
    %>
    </body>
    </html>
    And tell me How to find the absolute path of a file in JSP or JAVA?

  • Problem with file length in jsp IE it is working Firefox it is not workig

    Hi,
    I'm upload a file from the browser. i'm calculating the length i'm not getting the length of the file.
    The below shown code is working perfectly in IE and not working in Firefox.
    FileUpload.html
    <DOCTYPE>
    <HTML>
    <HEAD>
    <TITLE>Retailmint Jobs - Registration Form</TITLE>
    </HEAD>
    <BODY>
    <form>
    <table>
    <tr><td>Upload Resume :</td>
    <td> <input>
       </td>
    </tr>
    </table>
    <input>
    </p>
    <p>  </p>
    </form>
    </BODY>
    </HTML>
    FileUploadSubmit.jsp
    <page>
    <page>
    <page>
    <html>
    <head><title>Retailmint- Submission</title></head>
    <body>
    <FileInputStream>
    </body>
    </html>
    I find an error in firefox browser is not taking the fully qualified path
    i.e: C:\Documents and Settings\Administrator\Desktop\if.doc
    In firefox it is taking if.doc only.
    please tell me the solution.
    Regards
    venkat

    Sorry for that
    here is the code:
    FileUpload.html
    <HTML>
    <HEAD>
    <TITLE>Retailmint Jobs - Registration Form</TITLE>
    <script language="Javascript" src="FileRead.js">
    </script>
    </HEAD>
    <BODY>
    <form name='subregiform' method="get" action ="FileuploadSubmit.jsp" >
    <table width="566" border="0" cellspacing="0" cellpadding="0">
    <tr><td width="197"align="right">Upload Resume :</td>
    <td width="369"> <input type="file" name="file" value ="" onchange ="javascript:fopen('file');"><br>
       </td>
    </tr>     
    </table><br>
    <input type="submit" name="submit" value="Submit">
    </strong></p>
    <p>  </p>
    </form>
    </BODY>
    </HTML>
    FileUploadSubmit.jsp
    <%@ page import="java.text.*"%>
    <%@ page import="java.sql.*" %>
    <%@ page import="java.util.*" %>
    <%@ page import="java.io.*" %>
    <jsp:useBean id="DBase" class="dbconnection.DBconnection" scope="session" />
    <html>
    <head><title>Retailmint- Submission</title>
    </head>
    <body bgcolor="#e0e0e0">
    <%
    FileInputStream fis = new FileInputStream(request.getParameter("file"));
    len = (int)file.length();
                   System.out.println("length"+len);
    %>
    </body>
    </html>
    And tell me How to find the absolute path of a file in JSP or JAVA?

  • Problem with file length in jsp it is working in IE, not working Firefox

    Hi,
    I'm upload a file from the browser. i'm calculating the length i'm not getting the length of the file.
    The below shown code is working perfectly in IE and not working in Firefox.
    FileUpload.html
    <DOCTYPE>
    <HTML>
    <HEAD>
    <TITLE>Retailmint Jobs - Registration Form</TITLE>
    </HEAD>
    <BODY>
    <form>
    <table>
    <tr><td>Upload Resume :</td>
    <td> <input>
       </td>
    </tr>
    </table>
    <input>
    </p>
    <p>  </p>
    </form>
    </BODY>
    </HTML>
    FileUploadSubmit.jsp
    <page>
    <page>
    <page>
    <html>
    <head><title>Retailmint- Submission</title></head>
    <body>
    <FileInputStream>
    </body>
    </html>
    I find an error in firefox browser is not taking the fully qualified path
    i.e: C:\Documents and Settings\Administrator\Desktop\if.doc
    In firefox it is taking if.doc only.
    please tell me the solution.
    Regards
    venkat

    I agree with your words
    sorry for the code pasting.
    Here is the code:
    FileUpload.html
    <HTML>
    <HEAD>
    <TITLE>Retailmint Jobs - Registration Form</TITLE>
    </HEAD>
    <BODY>
    <form name='subregiform' method="get" action ="FileuploadSubmit.jsp" >
    <table width="566" border="0" cellspacing="0" cellpadding="0">
    <tr><td width="197"align="right">Upload Resume</td>
    <td width="369"> <input type="file" name="file" value ="" >
    </td>
    </tr>     
    </table>
    <input type="submit" name="submit" value="Submit">
    </form>
    </BODY>
    </HTML>
    FileUploadSubmit.jsp
    <%@ page import="java.text.*"%>
    <%@ page import="java.sql.*" %>
    <%@ page import="java.util.*" %>
    <%@ page import="java.io.*" %>
    <html>
    <head><title>Retailmint- Submission</title>
    </head>
    <body bgcolor="#e0e0e0">
    <%
    FileInputStream fis = new FileInputStream(request.getParameter("file"));
    len = (int)file.length();
    System.out.println("length"+len);
    %>
    </body>
    </html>
    And how to find the absolute path of a file in jsp or java
    Edited by: venkat.k on Sep 17, 2007 10:12 PM

  • File length different for a copied file. Or use checksum

    Hi
    I am making a backup of a file before doing some writes to the original.
    I first check it out of source control, then make a copy using:
    public static void backupFile(File f)
    try{
    File backup = new File(f.getPath()+"_BACKUP");
    if (!backup.exists()) {
    if (!backup.createNewFile()) {
    Logger.getLogger().log("Could not create "+backup.getPath());
    SystemTools.copyFile(f,backup);
    } catch (Exception e)
    Logger.getLogger().log("Error backing up "+f.getPath()+ ": "+e);
    public static synchronized void copyFile(File from, File to) throws Exception
    if (!from.exists() || !from.isFile())
    throw new Exception ("copyFile Error: checking 'from' file!");
    if (!to.exists())
    if(!to.createNewFile())
    throw new Exception ("copyFile Error: creating 'to' file!");
    FileInputStream in=new FileInputStream(from);
    FileOutputStream out=new FileOutputStream(to);
    int length;
    byte[] buffer=new byte[256];
    while((length=in.read(buffer))!=-1) {       
    out.write(buffer, 0, length);
    in.close();
    out.close();
    After writing has finished, I need to see if the file is different to the backup..
    If so, I need to check it into source control.
    I wanted to use a checksum, but couldn't find an example that actually worked!!! Therefore I did a quick tool:
    public static boolean isBackupIdenticalToOrig(File f) throws Exception {
    File bu = new File(f.getPath()+"_BACKUP");
    Logger.getLogger().log("Lengths: New/Backup"+f.length()+"/"+bu.length());
    if (bu.length()!=f.length())
    return false;
    // Have the same lengths, so we can compare!!
    BufferedInputStream f_in = null;
    BufferedInputStream bu_in= null;
    f_in =new BufferedInputStream (new FileInputStream (f));
    bu_in =new BufferedInputStream (new FileInputStream (bu));
    for (int i=0;i<f.length();i++)
    int c = f_in.read();
    int d = bu_in.read();
    if (c!=d)
    Logger.getLogger().log(""+f.getName()+" has been modified");
    return false;
    Logger.getLogger().log(""+f.getName()+" has not been modified");
    return true;
    The problem is in that the File.length() method is returning different values for the backup file, than for the original, even if identical!
    For example:
    10/15/2002 10:22:05: Lengths: New/Backup413/402
    10/15/2002 10:22:06: Lengths: New/Backup397/386
    10/15/2002 10:22:07: Lengths: New/Backup191/185
    All the new files are longer that the backup, but the contents are exactly the same! Is there some WIN32 'extras' in the file that's causing a problem here???
    In each of the cases, if I open the new(Longer) file in a good editor, I can see that the lengths are correct. But no extra characters existed in the new file compared to the backup!!
    Any ideas would be most appreciated
    Cheers
    Chris

    10 and 13 are CR(carriage return) and LF(linefeed) - this is normal for a Windows file. Use this copy routine; it works.
       // copyFile -  input: inFile -  path to source file
       //                    outFile - path to copy file to (including filename)
       //                    bRemoveSource - true removes the source files, false leaves them intact
       //             returns: void
       public static void copyFile(String inFile, String outFile,boolean bRemoveSource) throws IOException
          FileInputStream fin     = null;
          FileOutputStream fout   = null;
          boolean bCanWrite       = false;
          boolean bDeleted        = false;
          // To preserve date/time stamp
          File fTimeIn = new File(inFile);
          File fTimeOut = new File(outFile);
          long lTimeIn = fTimeIn.lastModified();
          try
            fin  = new FileInputStream(inFile);
            fout = new FileOutputStream(outFile);
            copyStream(fin, fout);
          finally
            try
              if (fin != null) fin.close();
            catch (IOException e) {}
            try
              if (fout != null) fout.close();
            catch (IOException e) {}
          fin.close();
          fout.close();
          // Set out time to in time
          fTimeOut.setLastModified(lTimeIn);
          if (bRemoveSource == true)
             bCanWrite = fTimeIn.canWrite();
             if (bCanWrite)  {
                bDeleted = fTimeIn.delete();
       // copyStream (a helper function for copyFile) -  input: in  - file stream of source file
       //                                                       out - file stream of destination file
       //                                                returns: void
       // *** NOTE: This function is thread safe ***
       public static void copyStream(InputStream in, OutputStream out)  throws IOException
          // do not allow other threads to read from the
          // input or write to the output while copying is
          // taking place
          synchronized (in)  {
             synchronized (out)  {
                byte[] buffer = new byte[256];
                while (true)  {
                   int bytesRead = in.read(buffer);
                   if (bytesRead == -1)
                      break;
                   out.write(buffer, 0, bytesRead);
       }

  • 1099 MISC 2011 file length

    Hi Experts
    This relates to 1099 MISC 2011 file length. We have applied SAP note 1666672 that pertains to 2011 changes.While the form print looks good, when i compared the file with P1220 ( The publication that specifies details on tax filing), i found that P1220 states that length of records should be 750 for the T and B records - however in my case i get only 746 characters
    I generated the file in txt and opened with excel and used LEN to count the length of the records
    Any suggestions? - Is there a further SAP note that is to be applied or a i  missing something on the DMEE side of it.
    Further is P1220 the Gospel to compare the correctness with.
    Thanks
    Swami

    HI swami,
    note 1666672 was updated  25th, please, review version 4.
    Also make sure you have applied the corrections or steps from notes
    1635493, 1673257 and and 1649356.
    Regards
    Madhu M

  • File.length issues

    I've been trying to make a terminal like program, but I've had issues detecting the file size. When I use file.length(), I get wildly different answers than use of the "du" unix command. Is this a bug in java? Mac OS X? Just me being an idiot?
    Thank you.

    They do different things for different purposes. du reports total disk usage, so it rounds up to the next block size. File.length() reports actual file size in bytes.

  • How can I check every 5 secs a file Length with Threads?

    As a matter of fact the subject is the main question.
    I need your HELP! PLEASEE!!

    import java.io.*;
    public class RFile implements Runnable {
         public static void main(String args[]) throws Throwable {
              RFile rf = new RFile(new File(args[0]));
              new Thread(rf).start();
         File file = null;
         public RFile(File f) {
              file = f;
         public void run() {
              try {
                   while (true) {
                        System.out.println(file.length());
                        Thread.sleep(5000);
              } catch (Throwable err) {};
    }

  • Unexpected problem; recently upgraded to version 3. Export of multiple tracks makes each file length same as longest file. Didn't do that in Vers2

    Unexpected problem; We rrecently upgraded to version 3. Export of multiple tracks in a multitrack session makes each file length same as longest file. Didn't do that in Vers 2 of soundtrack

    Hmm... Ok, so I took that project and tried importing it to a new project, still with no luck. Then I tried taking that project and creating a new timeline by dragging one of the stills to the new item icon so that I'd get whatever PrPro decided was the best timeline, and still no luck. Then I tried creating a new project and importing different footage and it worked. Tells me perhaps there's something wrong with the stills? I know not to use overly-large stills in a project, but they're all around 4k resolution or smaller... so surely that's not too big, right? 412 stills total 1.5GB which means an average of about 2.5 MB per file... certainly not too big. I even had a couple video clips in the timeline that were shot with a point-and-shoot still camera, and I tried taking those out just in case it was something in those, and still no success.
    So, ultimately this project got exported without CUDA, and I'm okay... but I also am wondering what caused the problem? I do a fair amount with stills (not a lot, but enough) and I need it to work... do I just go on with life, assuming that it was some weird fluke? Or do I try a complete wipe and reinstall of OS and Programs?
    Oh, one other tidbit... whenever PrPro crashed and closed, the application itself wouldn't close. I have to go into the program manager and force quit it...
    Thoughts? Recommendations?

  • File.length() too slow?

    I'm working on an application that needs to process directory listings on network fileserver, looking for files and directories, and getting basic info about files found (size, last modified date).
    I'm trying to use java.io.File.list(java.io.FileFilter) with java.io.FileFilter returning file.isDirectory() or file.isFile() to get a list of just files or directories, and try to get the rest of file information later for each of the returned Files. However, when it gets to a directory with a lot of files (13000+), it seem to be unacceptably slow. I have tracked it down to File.length(), taking up to 80ms per file (!), which amounts to only about 13 files per second.
    It's not a problem of the platform (Win XP), directory listing contianing all information I need takes less than 3 seconds for this big directory, while getting the same through Java APIs (calling isDirectory(), isFile(), length() and lastModified() within the FileFilter callback ) takes ages.
    Is there a better way to get a directory listing, without being orders of magnitude slower than necessary? I can think of calling native dir command and parsing the output, but that is a mess...

    I have tracked this down to native implementation of File.length() - VC++ runtime function _stati64 which they use to get file length is too slow.
    Why dont they use Windows API? I have tested that getting file size using GetFileAttributesEx() is at least 50x faster than _stati64 for my file!                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                       

  • Automatic file length setting for continuous recording?

    In iMovie 6 I was able to do long duration ( all night) recordings with automatic file splits at ten minutes. Hence, I would have 6 manageable files per hour.
    I can't find a way to set file lengths in iMovie 9.
    Is there some place in the preference files where I can set the length?
    Thank you in advance.
    Thomas

    Is there a length/size limit that GB can import?
    http://www.bulletsandbones.com/GB/GBFAQ.html#recordlength
    I made an 85-minute mp3 recording (with an Olympus LS-10) that does not successfully import
    http://www.bulletsandbones.com/GB/GBFAQ.html#PortableRecorderMp3s

  • Maximum Video file length in LR?

    What is the maximum Video file length LR 4x can Import and Edit?

    Hi a brody,
    Thanks for your comment.  I am running iPhoto 9.1.3.  Activity Monitor returns Intel as the type of process.  No clue if it is 32 or 64bit.
    How do I know if it is 32 or 64bit ? 
    Regards.

  • File length limit .mxf into Fcpx

    I am having problems importing .mxf files shot on canon 305 into fcpx.
    It does import the files - but only part of them.
    Is there a file length/size limit?
    Does anyone know why this might be happening?
    Thanks for any help.

    Hi Russ
    The files stop at 30 seconds each time.
    I have checked back at the source files and they are longer.

  • Does File length(size) varies from OS to OS??

    Hello Friends,
    I am in trouble I want to know that either File Length (size) vary from Operating system to Operating system or it does not vary.
    Why i want to know it I am using edt FTP client for which i want to test that my file has been uploaded correctly or not for this reason i can compare the files size of local and remote but i have doubt that file size varies from Os to OS. There may be different operating system for FTP server.
    So kindly tell me either file size differ on different operating systems or not.
    Thanks in advance.
    Abid

    uncle_alice wrote:
    ejp wrote:
    If the processor is written in Java it will understand the txt file with any of \r \n or \r\n as line terminators.If the processor is written correctly you mean. For example, if it uses BufferedReader.readLine() or Scanner.nextLine() to read the file, it won't matter what kind(s) of line separators the file uses. Unfortunately, there are still a great many programmers out there who insist on making life harder for everyone by using hand-rolled routines with hard-coded newlines.Of course if one, for example, wants to write code that runs on a linux server but which must create a file usable on a windows box then of course one must it fact use hard coded values.

Maybe you are looking for

  • FCP two monitors, 2nd won't display playback anymore

    I have two Cinema monitors specifically for working with FCP. The second monitor played what I see on my canvas for two weeks. When I started FCP the second monitor went black ready to play the canvas. It no longer does this. The first indication of

  • Reader X: DDE Open command can open Reader but not open a specified target PDF

    Once again Adobe has issued an update which breaks existing business systems. After the fiasco of Reader 9.3.4 failing to open external files such as SWF or XLS, the new Reader X is not opening the requested PDF when called via DDE. The Reader X alwa

  • On a PDF form, Save acts as if Save-As

    Windows XP SP3 Adobe Reader 10.1.1.33 I have started to fill out my U.S. federal tax forms for this year, just the names and address and a few checkboxes.  These are savable PDF files that I downloaded and saved from the IRS Web site.  I am doing thi

  • Length of com.sap.ide.webdynpro.uielementdefinitions.Resource

    Hi Experts, I've used the FileUpload control in a WebDynpro page. I'm using the CE 7.1 version of NWDS. This control has a Type property which I've bound to the following Simple Type: com.sap.ide.webdynpro.uielementdefinitions.Resource The default le

  • Lightsaber effect in Photoshop Elements 4.0- Please give some help

    Hi, I am very new to photo editing. I've been asked by my young cousins to photoshop in the lightsaber effect to some still photos. All I have is photoshop elements 4.0, and all the tutorials I find are in different editions. So far, I created the ad