
-----------------------------------
supahsain08
Sun Mar 30, 2008 6:14 pm

Need help in printing a line
-----------------------------------
hi, is it possible to post a line using coordinates, forexample if i want to post a line at the following coordinates (5,6)
Like I remember in Turing you can do that

For example here is the following code which shows all the directories and files

import java.io.*;
import java.util.*;
import java.text.*;
class Asn62
{
    public static void main (String [] args)
    {
    	
    	System.out.println ("\t\t\t\tDirectory\n");
            System.out.print ("Name");
            System.out.print ("\t                   Type");
            System.out.print ("\t\tLast Modified");
            System.out.println ("\t\t\tLength");
        String [] Directories;
        String [] Files;
        double [] Modified;
        double [] theLength;
        Files = new String [6] ;
        Directories = new String [6];
        Modified = new double [6];
        theLength = new double [6];
 
 
        File folder = new File ("F:/");
        File [] listOfFiles = folder.listFiles ();
 
        for (int i = 0 ; i < listOfFiles.length ; i++)
 
            {
                if (listOfFiles [i].isFile ())
                {
                    Files [0] = listOfFiles [i].getName ();
 
				System.out.println (Files [0]);
                }
                else if (listOfFiles [i].isDirectory ())
                {
                    Directories [0] = listOfFiles [i].getName ();
				System.out.print (Directories [0]);
				System.out.println("      Dir");
                }
 
                long t = listOfFiles [i].lastModified ();
 
                Modified [0] = t;
 
                long s = listOfFiles [i].length ();
                theLength [0] = s;    
 
            }         
    
}
}

Here is the output
http://i27.tinypic.com/2cp4aza.jpg 
(how do i post all dir's in one straight line)

-----------------------------------
HeavenAgain
Sun Mar 30, 2008 6:51 pm

RE:Need help in printing a line
-----------------------------------
printf or String.format() or Formatter class, use the "indent" flag
eg.System.out.printf("%10s%n","hi");
System.out.printf("%10s%n","supahsain08");

-----------------------------------
supahsain08
Sun Mar 30, 2008 7:08 pm

Re: Need help in printing a line
-----------------------------------
k i replaced this System.out.println ("Dir");
with this System.out.printf("%25s%n","Dir");
but still the same output
http://i28.tinypic.com/avoths.jpg

Any other suggestion?

-----------------------------------
HeavenAgain
Sun Mar 30, 2008 7:37 pm

RE:Need help in printing a line
-----------------------------------
System.out.printf("%-25s%s%n","myHomeWork","dir");
System.out.printf("%-25s%s%n","games","dir");the negative sign cause it to left(?) align text, and by default its right(?) aligned, so we change it and add the extra space we wanted

-----------------------------------
supahsain08
Sun Mar 30, 2008 7:52 pm

Re: Need help in printing a line
-----------------------------------
Thank you very much

Can you please help me one more time plz
I got that part now i need help with the last modified part, how will i format that correctly

http://i30.tinypic.com/idc101.jpg

Here is the code
import java.io.*;
import java.util.*;
import java.text.*;

class Asn62
{
    public static void main (String [] args)
    {
    	
    	System.out.println ("\t\t\t\tDirectory\n");
            System.out.print ("Name");
            System.out.print ("\t                      Type");
            System.out.print ("\tLast Modified");
            System.out.println ("\t\t\tLength");
            System.out.println ("");
        String [] Directories;
        String [] Files;
        double [] Modified;
        double [] theLength;
        Files = new String [6] ;
        Directories = new String [6];
        Modified = new double [6];
        theLength = new double [6];


        File folder = new File ("F:/");
        File [] listOfFiles = folder.listFiles ();

        for (int i = 0 ; i < listOfFiles.length ; i++)

            {
                if (listOfFiles [i].isFile ())
                {
                    Files [0] = listOfFiles [i].getName ();

				System.out.printf("%-30s%s%n",Files [0],"File");;
                }
                else if (listOfFiles [i].isDirectory ())
                {
                Directories [0] = listOfFiles [i].getName ();
                
                
                System.out.printf("%-30s%s%n",Directories [0],"Dir");
                
                
				
				
                }

                long t = listOfFiles [i].lastModified ();

                Modified [0] = t;
				System.out.println ("\t\t\t\t\t" + Modified [0]);
                long s = listOfFiles [i].length ();
                theLength [0] = s;
         

            }
  
}
}


EDIT: how will i add another another thing in this code, forexample if i want to add another word like "hi" after    35s?         System.out.printf("%-30s%s%n",Files [0],"File");; 

-----------------------------------
HeavenAgain
Sun Mar 30, 2008 8:18 pm

RE:Need help in printing a line
-----------------------------------
welcome :)
now, i have a question for you                double [] Modified;                
Modified = new double [6];
                long t = listOfFiles [i].lastModified ();
                Modified [0] = t;modified is an array of double, length of 6, ok, and now you are only making use of the first element, what's up with that? (unless i missed some part of course :?)

and now you have
            System.out.println ("\t\t\t\t\t" + Modified [0]); why cant you just do the same with the dir and file name?

and sorry i dont get your last question, what do you mean by, add hi after 35s? after 35 seconds? what is s :)

-----------------------------------
supahsain08
Sun Mar 30, 2008 8:24 pm

RE:Need help in printing a line
-----------------------------------
i think i figured it out

import java.io.*;
import java.util.*;
import java.text.*;

class Asn62
{
    public static void main (String [] args)
    {

        System.out.println ("\t\t\t\tDirectory\n");
        System.out.print ("Name");
        System.out.print ("\t                  Type");
        System.out.print ("\tLast Modified");
        System.out.println ("\t\t       Length (bytes)");
        System.out.println ("");
        String [] Directories;
        String [] Files;
        double [] Modified;
        double [] theLength;
        Files = new String [6];
        Directories = new String [6];
        Modified = new double [6];
        theLength = new double [6];


        File folder = new File ("F:/");
        File [] listOfFiles = folder.listFiles ();

        for (int i = 0 ; i < listOfFiles.length ; i++)

            {

                long t = listOfFiles [i].lastModified ();

                Modified [0] = t;

                long s = listOfFiles [i].length ();
                theLength [0] = s;


                if (listOfFiles [i].isFile ())
                {
                    Files [0] = listOfFiles [i].getName ();

                    System.out.printf ("%-26s%s%-3s%s%-3s%s%n", Files [0], "FIL", "", new Date (t), "", theLength [0]);
                }
                else if (listOfFiles [i].isDirectory ())
                {
                    Directories [0] = listOfFiles [i].getName ();

                    System.out.printf ("%-26s%s%-3s%s%-3s%s%n", Directories [0], "DIR", "", new Date (t), "", theLength [0]);

                }

            }

    }
}

Output
http://i28.tinypic.com/4uf4u8.jpg


Thanks again :)
