Page 2 of 4 FirstFirst 1234 LastLast
Results 11 to 20 of 34

Thread: Your computer clock maybe wrong......

  1. #11
    TheDave's Avatar n00b
    Join Date
    Apr 2003
    Location
    yorkshire, england
    Age
    38
    Posts
    6,726
    could be made to sync time though

    i started teaching myself java then errr stopped

  2. Lounge   -   #12
    Sample output
    Attached Images Attached Images

  3. Lounge   -   #13
    DarthInsinuate's Avatar Died in battle
    Join Date
    Jan 2003
    Location
    Arkham Asylum
    Posts
    4,872
    Quote Originally Posted by TheDave


    yep it does
    i broke mine, Windows won't ever have the precision of 10 seconds again
    The Sexay Half Of ABBA And Max: Freelance Plants

  4. Lounge   -   #14
    Quote Originally Posted by TheDave
    could be made to sync time though

    i started teaching myself java then errr stopped
    Yeah, I suppose it could be modified to sync the time. I've been learning java for about a year and a half now, but they don't teach us much to do with interaction with windows (and I can't be fecked learning )

  5. Lounge   -   #15
    TheDave's Avatar n00b
    Join Date
    Apr 2003
    Location
    yorkshire, england
    Age
    38
    Posts
    6,726
    i wish they taught it in pill form, that would be cool

  6. Lounge   -   #16
    enoughfakefiles's Avatar Ad ministrator
    Join Date
    Jun 2003
    Location
    I'm an Even Steven with a
    Posts
    7,568
    Quote Originally Posted by TheDave
    i wish they taught it in pill form, that would be cool
    The blue pill or the red pill.

  7. Lounge   -   #17
    Code:
    import java.io.*;
    
    public class FileMover
    {
    	public static void main (String[] args) throws IOException
    	{
    		BufferedReader in = new BufferedReader(new InputStreamReader(System.in));
    		
    		System.out.print("Enter the filename you wish to move: ");
    		String fileToBeMoved = in.readLine();
    		File file = new File (fileToBeMoved);
    		
    		while(!file.exists())
    		{
    			System.out.println("The file you've entered does not exist.\nPlease try again: ");
    			fileToBeMoved = in.readLine();
    			file = new File (fileToBeMoved);
    		}
    		
    		long fileLength = file.length();
    		
    		System.out.print("Enter the destination path: ");
    		String destpath = in.readLine();
    		
    		File dir = new File(destpath);
    		
    		String pathname = file.getAbsolutePath();
    		
    		System.out.println("\nYou are about to move: \n\n"+pathname+"\nto \n"+destpath);
    		System.out.print("\nIf you're happy with this, enter 'y' to proceed.\nOtherwise press 'n' to cancel: ");
    		
    		char userInput = (char) System.in.read();
    		
    		if(userInput == 'y')
    		{
    			double start = System.currentTimeMillis();
    			boolean fine = file.renameTo(new File(dir, file.getName()));
    			double end = System.currentTimeMillis();
    			double timeTaken = (end - start)/1000;
    			
    			if(fine)
    			{
    				if(timeTaken > 0)
    				{
    					double transferRate = ((fileLength/1024)/timeTaken);
    					System.out.println("\nFile "+fileToBeMoved+" is "+fileLength+" bytes and took "+timeTaken+" seconds to move");
    					System.out.println("Average transfer rate was "+Math.round(transferRate)+" kB/sec");
    				}
    				else
    					System.out.println("\nFile moved successfully");
    			}
    			else
    				System.out.println("\nFile not moved");
    		}
    		else
    			System.out.println("\nYou have cancelled the move\n");
    	}
    }
    A FileMoving program I made. It takes about 50-75% of the time windows takes to move the same file (which is quite surprising considering how slow java is in comparison to 'real' languages)

  8. Lounge   -   #18
    Code:
    import java.io.*;
    
    public class FileMover
    {
    	public static void main (String[] args) throws IOException
    	{
    		BufferedReader in = new BufferedReader(new InputStreamReader(System.in));
    		// Set up BufferedReader to take user input
    		
    		System.out.print("Enter the filename you wish to move: ");
    		
    		String fileToBeMoved = in.readLine();
    		// Read in the pathname from a user of the file they wish to move
    		
    		File file = new File (fileToBeMoved);
    		// Create a new file object with the path from above
    		
    		while(!file.exists()) // While they don't enter a real file
    		{
    			System.out.println("The file you've entered does not exist.\nPlease try again: ");
    			// Tell them they didn't enter a real file
    			fileToBeMoved = in.readLine();
    			// Read in a new pathname
    			
    			file = new File (fileToBeMoved);
    			// Create new file object...
    		}
    		
    		long fileLength = file.length();
    		// Get length of the file to be moved
    		
    		System.out.print("Enter the destination path: ");
    		String destpath = in.readLine();
    		// Read in destination path from user
    		
    		File dir = new File(destpath);
    		// Create a new using the destination path from the user
    		
    		String pathname = file.getAbsolutePath();
    		// Get the full path of the file the user inputs (e.g. C:\Windows\System32\winmine.exe)
    		
    		System.out.println("\nYou are about to move: \n\n"+pathname+"\nto \n"+destpath);
    		System.out.print("\nIf you're happy with this, enter 'y' to proceed.\nOtherwise press 'n' to cancel: ");
    		
    		char userInput = (char) System.in.read();
    		// Read in one char from the user
    		
    		if(userInput == 'y') // If the user enters a 'y' (i.e. they want to move the file)
    		{
    			double start = System.currentTimeMillis();
    			// Get current system time (to be used in calculation later
    			
    			boolean fine = file.renameTo(new File(dir, file.getName()));
    			// Move the file (by renaming the path)
    			// Set the boolean value "fine" to true if the transfer goes OK, otherwise set it to false
    			
    			double end = System.currentTimeMillis();
    			// Get current system time (after the move operation)
    			
    			double timeTaken = (end - start)/1000;
    			// Calculate how long it took to move the file (division by 1000 gives result in seconds)
    			
    			if(fine) // If the file move went OK
    			{
    				if(timeTaken > 0) // If it took more than "0" time to move (to counter possible division by 0)
    				{
    					double transferRate = ((fileLength/1024)/timeTaken); 
    					// Calculate transfer rate for the file
    					
    					System.out.println("\nFile "+fileToBeMoved+" is "+fileLength+" bytes and took "+timeTaken+" seconds to move");
    					System.out.println("Average transfer rate was "+Math.round(transferRate)+" kB/sec");
    				}
    				else // If it didn't take more than "0" seconds
    					System.out.println("\nFile moved successfully");
    			}
    			else // If "fine" is false (i.e. if there was a problem with the move
    				System.out.println("\nFile not moved");
    		}
    		else // If the user cancelled the transfer (by entering other than 'y' above)
    			System.out.println("\nYou have cancelled the move\n");
    	}
    }
    Commented version of above (if anyone wants to learn anything from it

    Sample run (obviously it's simple with no real GUI):
    Attached Images Attached Images
    Last edited by Tifosi; 11-30-2004 at 09:40 PM.

  9. Lounge   -   #19
    lynx's Avatar .
    Join Date
    Sep 2002
    Location
    Yorkshire, England
    Posts
    9,759
    Quote Originally Posted by Tifosi
    Code:
    import java.io.*;
    
    public class FileMover
    {
    	public static void main (String[] args) throws IOException
    	{
    		BufferedReader in = new BufferedReader(new InputStreamReader(System.in));
    		
    		System.out.print("Enter the filename you wish to move: ");
    		String fileToBeMoved = in.readLine();
    		File file = new File (fileToBeMoved);
    		
    		while(!file.exists())
    		{
    			System.out.println("The file you've entered does not exist.\nPlease try again: ");
    			fileToBeMoved = in.readLine();
    			file = new File (fileToBeMoved);
    		}
    		
    		long fileLength = file.length();
    		
    		System.out.print("Enter the destination path: ");
    		String destpath = in.readLine();
    		
    		File dir = new File(destpath);
    		
    		String pathname = file.getAbsolutePath();
    		
    		System.out.println("\nYou are about to move: \n\n"+pathname+"\nto \n"+destpath);
    		System.out.print("\nIf you're happy with this, enter 'y' to proceed.\nOtherwise press 'n' to cancel: ");
    		
    		char userInput = (char) System.in.read();
    		
    		if(userInput == 'y')
    		{
    			double start = System.currentTimeMillis();
    			boolean fine = file.renameTo(new File(dir, file.getName()));
    			double end = System.currentTimeMillis();
    			double timeTaken = (end - start)/1000;
    			
    			if(fine)
    			{
    				if(timeTaken > 0)
    				{
    					double transferRate = ((fileLength/1024)/timeTaken);
    					System.out.println("\nFile "+fileToBeMoved+" is "+fileLength+" bytes and took "+timeTaken+" seconds to move");
    					System.out.println("Average transfer rate was "+Math.round(transferRate)+" kB/sec");
    				}
    				else
    					System.out.println("\nFile moved successfully");
    			}
    			else
    				System.out.println("\nFile not moved");
    		}
    		else
    			System.out.println("\nYou have cancelled the move\n");
    	}
    }
    A FileMoving program I made. It takes about 50-75% of the time windows takes to move the same file (which is quite surprising considering how slow java is in comparison to 'real' languages)
    The only reason that java is slower than 'real' languages is because it has to be interpreted first. If that is a relatively small part of the procedure compared to the actual work done there is no reason why it shouldn't work almost as fast.

    Your claim that it is faster than windows doing the same file move is almost certainly wrong. When windows moves a file, it has actually finished moving it when it says it has finished. In contrast the java program hands that task over to windows. Windows will have cached some of the move and allowed the java program to continue. Windows will still be moving the file while your program is waiting for you to "Press any key to continue...".
    .
    Political correctness is based on the principle that it's possible to pick up a turd by the clean end.

  10. Lounge   -   #20
    ZaZu's Avatar I know stuff ...
    Join Date
    Sep 2003
    Location
    @Home
    Posts
    1,916
    The gov time server is the atomic one not Microsloth



    If you attack the establishment long enough and hard enough, they will make you a member of it.
    -- Art Buchwald --

Page 2 of 4 FirstFirst 1234 LastLast

Bookmarks

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •