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.

Similar Messages

  • File length issue

    Hi,
    I have a client trying to copy files from his Panther OS machine to our Mac OS X server ( v10.5.3 ). He says that he gets an message that file name too long. Is there a file name length limit in play between these 2 machines?
    Thanks

    Hi,
    Got some further info from user.
    He is using Panther OS , and file name is 'Barloworld.indd'.
    Trying to copy file to a 'smb' share on our 10.5.3 Mac OS X server.
    Message he gets is :
    You cannot copy the item 'Barloworld.indd' because the name is too long or includes characters that the disk cannot display.

  • File renameto issue

    I have been tracking this down for a couple of days now and thought I would ask the forum for their input.
    I have a very simple process that opens a file, reads in the data, writes some data to a DB, and them moves the file to a processed folder.
    SOME of the instances I have running that are performing this process are moving the files into the wrong directory. I am going round and round with this
    being an OS issue and/or jvm issue. The oddest thing is that the wrong directory that some of the processes write their files to is always the last
    directory created under that particular filesystem.
    System:
    sun-jdk-1.5.0.06
    Linux; SMP; 2.6.12
    Process is run via shell script every 10 minutes where a directory is passed to the process, the process then looks in the directory for files,
    does what it does, and then renames the file. ex. "LogProcessor /var/log/10.5.1.2/". The process should move the file to the folder /var/log/10.5.1.2/processed,
    instead it is moving the file to "/var/log/10.5.1.52/processed". All of the debug code you see below is telling me that everything is what and where it should
    be, however, it is not.
    Other information: There are about 15 independent processes running started by separate shell scripts and all should be reading and writing to their respective folders.
    Any input would be greatly appreciated.
    CODE:
    File dirName = new File(args[0]);
    String[] files = dirName.list();
    //test if directory actually has something we want
                   if (files != null) {
                        // loop through list of files found in directory
              for (int i=0; i<files.length; i++) {
              // Get filename of file or directory
                   if(debug)
                        System.err.println("File Extension: " + files.substring(files[i].length() - 3));
                   // test last 3 characters for file extension we need
                   if (files[i].substring(files[i].length() - 3).equalsIgnoreCase("log") || files[i].substring(files[i].length() - 3).equalsIgnoreCase("alm")) {
              fileName = args[0] + files[i];
                   // Call each method respectively passing in all the local objects
                   if (alarms) {
                                       logProcessor.alarmsProcessor(fileName, logFile, job, jobActions, errors, debug);
                                  } else {
                                       logProcessor.storeLogsProcessor(fileName, logFile, job, jobActions, errors, debug);
                   //SLD 11/28/2007: move the file to the processed folder after read
                   File file1 = new File(fileName); //this file already existed on the file system
                   File file2 = new File(args[0]+"processed/"+files[i]);
                        if (file1.renameTo(file2)) {
                             System.out.println("File "+files[i]+" Moved to processed folder "+ args[0] + "processed" + file2.toString());
                             System.out.println("From: " + file1.toString() + " To: " + file2.toString() );
                        } else {
                             System.out.println("File "+files[i]+" NOT Moved to processed folder "+ args[0] + " due to either permissions, folder nonexistant or file already exists");

    Well, just to update the issue. The problem has been solved. There was an entry into the list of IP's that was 10.58.?.??, which in the unix world is a special character/place holder for all
    files/folders that resemble it. This was wreaking havoc on my java program when moving files.
    Thanks,

  • File attachment issue in MimeMessage [Mail API]

    Hi,
    I tried to attach PDF and XML file in MIME Message of MAIL API. I want attach encoded PDF and XML file with gzip format.
    I’m able to attached both the files but its not attached properly and when i tried to retrieved back from MIME Message, I’m getting error.
    Error is
    java.util.zip.ZipException: oversubscribed literal/length tree
         at java.util.zip.InflaterInputStream.read(InflaterInputStream.java:147)
         at java.util.zip.GZIPInputStream.read(GZIPInputStream.java:92)
         at java.io.FilterInputStream.read(FilterInputStream.java:90)
         at com.asite.supernova.test.CreateReadMimeMessage.ReadMail1(CreateReadMimeMessage.java:145)
         at com.asite.supernova.test.CreateReadMimeMessage.main(CreateReadMimeMessage.java:48)
    Here my code
    import java.io.BufferedInputStream;
    import java.io.BufferedOutputStream;
    import java.io.BufferedReader;
    import java.io.BufferedWriter;
    import java.io.ByteArrayOutputStream;
    import java.io.File;
    import java.io.FileInputStream;
    import java.io.FileNotFoundException;
    import java.io.FileOutputStream;
    import java.io.FileWriter;
    import java.io.IOException;
    import java.io.InputStream;
    import java.io.InputStreamReader;
    import java.io.OutputStream;
    import java.io.Reader;
    import java.io.StringWriter;
    import java.io.Writer;
    import java.util.Date;
    import java.util.Enumeration;
    import java.util.Properties;
    import java.util.zip.CRC32;
    import java.util.zip.Deflater;
    import java.util.zip.GZIPInputStream;
    import java.util.zip.GZIPOutputStream;
    import java.util.zip.ZipEntry;
    import java.util.zip.ZipOutputStream;
    import javax.activation.DataHandler;
    import javax.activation.DataSource;
    import javax.mail.BodyPart;
    import javax.mail.Header;
    import javax.mail.Message;
    import javax.mail.Multipart;
    import javax.mail.Session;
    import javax.mail.internet.MimeBodyPart;
    import javax.mail.internet.MimeMessage;
    import javax.mail.internet.MimeMultipart;
    import org.apache.commons.codec.binary.Base64;
    import com.sun.istack.internal.ByteArrayDataSource;
    public class CreateReadMimeMessage {
         public static void main(String[] args) {
              CreateMail();
              ReadMail1();
         public static void CreateMail(){
              try{
                   Properties properties = System.getProperties();
                 Session session = Session.getDefaultInstance(properties);
                 Message msg = new MimeMessage(session);
                 msg.setSentDate(new Date());            
                 Multipart multipart = new MimeMultipart();
                 BodyPart part1 = new MimeBodyPart();           
                 part1.setFileName("test.pdf");                               
                 part1.setHeader("Content-Type", "application/pdf");
                 part1.setHeader("Content-Encoding", "gzip");
                 part1.setHeader("Content-ID", "PDF");
                 //1
                 compressFile("test.pdf","testpdf.gzip");
                 String encodedData = new String(getBytesFromFile(new File("testpdf.gzip")));
                 //1
                 DataSource ds = new ByteArrayDataSource(encodedData.getBytes(), "application/pdf");            
                 DataHandler dh = new DataHandler(ds);
                 part1.setDataHandler(dh);
                 //part1.setText("This is only text data");
                 BodyPart part2 = new MimeBodyPart();
                 part2.setFileName("test.xml");
                 part2.setHeader("Content-Type", "application/xml;");
                 part2.setHeader("Content-Encoding", "gzip");
                 part2.setHeader("Content-ID", "XML");
                 part2.setHeader("Content-Transfer-Encoding", "base64");
                 //1
                 compressFile("test.xml","textxml.gzip");
                 String dataXML = new String(getBytesFromFile(new File("textxml.gzip")));
                 DataSource ds1 = new ByteArrayDataSource(dataXML.getBytes(), "application/xml");
                 DataHandler dh1 = new DataHandler(ds1);
                 part2.setDataHandler(dh1);            
                 multipart.addBodyPart(part1);
                 multipart.addBodyPart(part2);
                 msg.setContent(multipart);
                 msg.writeTo(new FileOutputStream(new File("MIMEMessage.xml")));
              }catch (Exception e) {
                   // TODO: handle exception
                   e.printStackTrace();
         public static void ReadMail1(){
              try{
                   Properties properties = System.getProperties();
                 Session session = Session.getDefaultInstance(properties);
                 InputStream inFile = new FileInputStream(new File("MIMEMessage.xml"));
                 Message msg = new MimeMessage(session,inFile);     
                Multipart multipart = (Multipart) msg.getContent();
                for (int i = 0; i < multipart.getCount(); i++) {              
                    BodyPart bodyPart = multipart.getBodyPart(i);
                    Enumeration enumHeader = bodyPart.getAllHeaders();
                    String fileExt="";
                    while(enumHeader.hasMoreElements()){
                         Header header = (Header) enumHeader.nextElement();
                         System.out.println(header.getName() + ":" + header.getValue());
                         if(header.getName().equalsIgnoreCase("Content-ID")){
                              if(header.getValue().equalsIgnoreCase("pdf")){
                                   fileExt=".pdf";
                              }else if(header.getValue().equalsIgnoreCase("xml")){
                                   fileExt=".xml";
                    BufferedInputStream inn = new BufferedInputStream(bodyPart.getInputStream());
                    GZIPInputStream gzin = new GZIPInputStream(inn);
                    // Open the output file
                       String target ="File"+i+fileExt;
                       OutputStream outf = new FileOutputStream(target);
                       // Transfer bytes from the compressed file to the output file
                       byte[] buff = new byte[128];
                       int lent;
                       while ((lent = gzin.read(buff)) > 0) {
                            outf.write(buff, 0, lent);
              }catch (Exception e) {
                   // TODO: handle exception
                   e.printStackTrace();
         public static void compressFile(String input,String output) {
              try {
                   // Create the GZIP output stream               
                   OutputStream out = new GZIPOutputStream(new FileOutputStream(output));
                   out =new BufferedOutputStream(out);
                   // Open the input file
                   //FileInputStream in = new FileInputStream(input);
                   InputStream in = new BufferedInputStream(new FileInputStream(input));
                   // Transfer bytes from the input file to the GZIP output stream
                   byte[] buf = new byte[524288];
                   /*int len;
                   while ((len = in.read(buf)) > 0) {
                        out.write(buf, 0, len);
                   int count;
                   while((count = in.read(buf, 0, 524288)) != -1) {
                        System.out.println(new String(buf, 0, count));
                        out.write(buf, 0, count);
                   out.flush();
                   in.close();
                   // Complete the GZIP file
                   //out.finish();
                   out.close();               
              } catch (Exception e) {
                   e.printStackTrace();
         public static byte[] getBytesFromFile(File file) throws IOException {
            InputStream is = new FileInputStream(file);
            // Get the size of the file
            long length = file.length();
            if (length > Integer.MAX_VALUE) {
                // File is too large
            System.out.println("File Len : " + length);
            // Create the byte array to hold the data
            byte[] bytes = new byte[(int)length];
            // Read in the bytes
            int offset = 0;
            int numRead = 0;
            while (offset < bytes.length
                   && (numRead=is.read(bytes, offset, bytes.length-offset)) >= 0) {
                offset += numRead;
            System.out.println("offset : " + offset);
            // Ensure all the bytes have been read in
            if (offset < bytes.length) {
                throw new IOException("Could not completely read file "+file.getName());
            // Close the input stream and return bytes
            is.close();
            return bytes;
    }Please help me asap.
    Edited by: sabre150 on 10-Feb-2011 01:50
    Moderator action : added [ code] tags to make the code readable.

    String is not a suitable container for binary data so unless the two lines
                 compressFile("test.pdf","testpdf.gzip");
                 String encodedData = new String(getBytesFromFile(new File("testpdf.gzip")));actually Base64 encode the file content you are probably corrupting your file.
    I suspect you should be Base64 encoding the compressed file and modifying the mime-type to reflect this.

  • 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

  • PS CS3, Camera Raw 4.6 Update and Nikon D810 NEF File Reading Issue

      Currently Have Photoshop CS3 & Adobe Bridge CS3 2.1.1.9.
    According to Adobe, Camera Raw 4.6 supports Nikon D810 NEF files.  I have downloaded Camera Raw 4.6 Update. When
    I try to open Nikon D810 NEF files, I get Photoshop CS3  error that says
    "cannot complete request your because it is not the right kind of
    document. These NEF files wont open in Adobe Bridge at all.  What am I doing wrong?

    Hey,
    Before I purchased, let me get your thoughts on another option that just occurred to me which involves:
    1)Editing my D810 NEF files in LR 5.6, which I have, then exporting/saving the edited files as JPEGs.
    2) Doing any additional editing, as necessary (i.e. that might require layering or selections..etc) , with the JPEGs  with Bridge or PS CS3. 
    This method wont involve any additional software purchase now.. right?    Am I missing anything.   here?    Since my final output to my customers are JPEGs any way, wont this work?   Will I be at any disadvantage.   Am I missing anything.   here? 
    From: ssprengel <[email protected]>
    To: charles cash <[email protected]>
    Sent: Monday, October 6, 2014 9:49 AM
    Subject:  PS CS3, Camera Raw 4.6 Update and Nikon D810 NEF File Reading Issue
    PS CS3, Camera Raw 4.6 Update and Nikon D810 NEF File Reading Issue  created by ssprengel in Adobe Camera Raw - View the full discussion  
    You can buy it from here:
    http://creative.adobe.com/plans
    Please note that the Adobe Forums do not accept email attachments. If you want to embed a screen image in your message please visit the thread in the forum to embed the image at https://forums.adobe.com/message/6795004#6795004
    Replies to this message go to everyone subscribed to this thread, not directly to the person who posted the message. To post a reply, either reply to this email or visit the message page: 
    To unsubscribe from this thread, please visit the message page at . In the Actions box on the right, click the Stop Email Notifications link. 
    Start a new discussion in Adobe Camera Raw by email or at Adobe Community
    For more information about maintaining your forum email notifications please go to http://forums.adobe.com/thread/416458?tstart=0.

  • Duplicate File Handling Issues - Sender File Adapter - SAP PO 7.31 - Single Stack

    Hi All,
    We have a requirement to avoid processing of duplicate files. Our system is PI 7.31 Enh. Pack 1 SP 23. I tried using the 'Duplicate File Handling' feature in Sender File Adapter but things are not working out as expected. I processed same file again and again and PO is creating successful messages everytime rather than generating alerts/warnings or deactivating the channel.
    I went through the link  Michal's PI tips: Duplicate handling in file adapter - 7.31  . I have maintained similar setting but unable to get the functionality achieved. Is there anything I am missing or any setting that is required apart from the Duplicate file handling check box and a threshold count??
    Any help will be highly appreciated.
    Thanks,
    Abhishek

    Hello Sarvjeet,
    I'd to write a UDF in message mapping to identify duplicate files and throw an exception. In my case, I had to compare with the file load directory (source directory) with the archive directory to identify whether the new file is a duplicate or not. I'm not sure if this is the same case with you. See if below helps: (I used parameterized mapping to input the file locations in integration directory rather than hard-coding it in the mapping)
    AbstractTrace trace;
        trace = container.getTrace();
        double archiveFileSize = 0;
        double newFileSizeDouble = Double.parseDouble(newFileSize);
        String archiveFile = "";
        String archiveFileTrimmed = "";
        int var2 = 0;
        File directory = new File(directoryName);
        File[] fList = directory.listFiles();
        Arrays.sort(fList, Collections.reverseOrder());
        // Traversing through all the files
        for (File file : fList){   
            // If the directory element is a file
            if (file.isFile()){       
                            trace.addInfo("Filename: " + file.getName()+ ":: Archive File Time: "+ Long.toString(file.lastModified()));
                            archiveFile = file.getName();
                          archiveFileTrimmed = archiveFile.substring(20);       
                          archiveFileSize = file.length();
                            if (archiveFileTrimmed.equals(newFile) && archiveFileSize == newFileSizeDouble ) {
                                    var2 = var2 + 1;
                                    trace.addInfo("Duplicate File Found."+newFile);
                                    if (var2 == 2) {
                                            break;
                            else {
                                    continue;
        if (var2 == 2) {
            var2 = 0;
            throw new StreamTransformationException("Duplicate File Found. Processing for the current file is stopped. File: "+newFile+", File Size: "+newFileSize);
    return Integer.toString(var2);
    Regards,
    Abhishek

  • 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

  • SQL Server 2008 .MDF File attaching issue

    Hy all guys here is big Happy news about the SQL Server 2008 database.mdf file attaching issue on Windows 8.1 and SQL Server 2008
    I found the solution like this
    first you go to the directory of your computer and go to that folder where your database and other files are like
    folder having database and files then > Right click and > security > then give full rights from which user you LOGIN and then apply > ok after that go to SQL Server 2008 > Right Click > run as administrator
    Hurray your problem will be resolve I Resolved my issue too  thanks to providing every solution
    if you guys find solution please give me best regards thanks  

    Hi Farhan-Islam,
    Glad to hear that your issue had been solved by yourself. Thank you for your sharing which will help other forum members who have the similar issue.
    Regards,
    Lydia Zhang

  • 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?

Maybe you are looking for

  • Solaris 10 installation on x86 problem: reboot

    Having downloaded and burned 4 cd iso images I tried to install Solaris 10 on my system. But - on the very beginning it (the installer) reboots my computer and this happens every time I try to install - a few seconds after I see "loading kernel/unix.

  • Upgrade to 9.2.0.8 from 9.2.0.6

    Hi, Is p4547809_92080_WINNT.zip the correct patch set to upgrade to 9.2.0.8 from 9.2.0.6 ? We are on Win 2003 server. DB is 9.2.0.6. Many thanks.

  • Very urgent regarding ALV

    Hi all, I have displayed data in alv.and the error condition is that if for a material if it has more than one S as ok_status records then it should throw an error. This logic is working fine. Now suppose at first time user had entered S through keyb

  • How to disable context menus hiding when accidentally clicking non-text?

    I have Googled and searched the Apple support board for this everywhere, and cannot find this addressed specifically. What I would like to do is disable how the context menu (for toolbars, right click, whatever)  automatically disappears if you accid

  • Pc card on sup error

    Hi Expert! when i have insert the pc card inside the sup 1 and i issue the command dir slot0:;i have received the following error:error = -24 Open device slot0 failed (bad device info block).the pc card didn't contain a key protection. 10xs Ali