Professional Documents
Culture Documents
Practical File
multiply[c][d] = sum;
sum = 0;
System.out.print("\n");
p-5 Write a Java program that reads a file name from the
user, then displays information
about whether the file exists, whether the file is
readable, whether the file is writable, the type of file and
the length of the file in bytes.
import java.io.*;
import java.util.*;
class FileTest
{
public static void main (String ar[])
{
String a;
Scanner in=new Scanner(System.in);
System.out.println("Please entre the file to be tested.");
a=in.nextLine();
File f1 = new File (a);
System.out.println("File Exists -");
System.out.println(f1.exists());
System.out.println("File is readable - ");
System.out.println(f1.canRead());
System.out.println("File is writable - ");
System.out.println(f1.canWrite());
System.out.println("File is a regular file -");
System.out.println(f1.isFile());
System.out.println("File is a directory - ");
System.out.println(f1.isDirectory());
System.out.println("Length of file=");
System.out.println(f1.length());
}
}
}
}
}
for(int i=1;i<a+1;i++)
{
fact=fact*i;
}
t2.setText(" "+fact);
}
class Thread2 extends Thread
{
public void run()
{
for(int i=0;i<=10;i++)
{
try
{
System.out.println("Thread 2: "+i+"time Good night ");
Thread.sleep(3500);
}
catch(InterruptedException IE)
{
IE.getMessage();
}
}
}
}
class Intrest
{
public static void main(String [] args)
{
System.out.println("Program to perform multiThreading");
Thread1 t1=new Thread1();
Thread2 t2=new Thread2();
t1.start();
t2.start();
for(int i=0;i<=10;i++)
{
try
{
System.out.println("Main Thread "+i+"time : Hi");
Thread.sleep(1000);
}
catch(InterruptedException IE)
{
IE.getMessage();
}
}
}
b3.addActionListener(this);
b4=new Button("DIV");
add(b4);
b4.addActionListener(this);
b5=new Button("C");
add(b5);
b5.addActionListener(this);
}
public void actionPerformed(ActionEvent e)
{
int x=Integer.parseInt(t1.getText());
int y=Integer.parseInt(t2.getText());
if(e.getSource()==b1)
{
int sum=x+y;
t3.setText(" "+sum);
showStatus("Text and Button Events Performed");
repaint();
}
if(e.getSource()==b2)
{
int sub=x-y;
t3.setText(" "+sub);
showStatus("Text and Button Events Performed");
repaint();
}
if(e.getSource()==b3)
{
int mul=x*y;
t3.setText(" "+mul);
showStatus("Text and Button Events Performed");
repaint();
}
try{ if(e.getSource()==b4)
{
int div=x/y;
t3.setText(" "+div);
showStatus("Text and Button Events Performed");
repaint();
}
}
catch (Exception ArithmeticException)
{
System.out.print("Arithmetic Exception");
}
if(e.getSource()==b5)
t1.setText(" ");
t2.setText(" ");
t3.setText(" ");
showStatus("Text and Button Events Performed");
repaint();
}