import java.io.*;//调入和io相关的类 class fileinfo{ file&://注/意,main函数一定是静态方法
public static void main(String args[])throws IOException{ File fileToCheck;//使用文件对象创建实例 if (args.length>0){ for (int i=0;i<args.length;i++){ fileToCheck=new File(args[i]);//为文件对象分配空间 info(fileToCheck);//这里引用的info一定要是静态方法成员 } } else{ System.out.println("no file given"); } }
public static void info(File f)throws IOException{ System.out.println("Name:"+f.getName()); System.out.println("Path:"+f.getPath()); if (f.exists()){ System.out.println("File exists."); System.out.print((f.canRead()?" and is Readable":""));//判定函数,假如满足条件,输出前者,否则输出后者 System.out.print((f.canWrite()?"and is Writable":"")); System.out.print("."); System.out.println("File is"+f.length()+"bytes."); } else{ System.out.println("File does not exist."); } } }
class phones{ static FileOutputStream fos; public static final int lineLength=81; public static void main(String args[])throws IOException{ byte[] phone=new byte[lineLength]; byte[] name=new byte[lineLength]; int i; fos=new FileOutputStream("phone.numbers"); while(true){ System.err.println("Enter a name(enter ´´done´´ to quit)"); readLine(name); if ("done".equalsIgnoreCase(new String(name,0,0,4))){ break; } System.err.println("Enter the phone number"); readLine(phone); for (i=0;phone[i]!=0;i++){ fos.write(phone[i]); } fos.write(´´,´´); for (i=0;name[i]!=0;i++){ fos.write(name[i]); } fos.write(´´´´); } fos.close(); }
public class RemoteFileServer { protected int listenPort = 3000; public static void main(String[] args) { } public void acceptConnections() { } public void handleConnection(Socket incomingConnection) { } }