Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- import java.io.*;
- import java.util.List;
- import java.util.Scanner;
- import java.util.StringTokenizer;
- public class Main
- {
- public static void readFile( String path )
- {
- Scanner scanner = null;
- File file = new File( path );
- StringTokenizer st;
- try {
- scanner = new Scanner(file);
- while (scanner.hasNextLine() )
- {
- //System.out.println( scanner.nextLine() );
- st = new StringTokenizer( scanner.nextLine(), " " );
- while ( st.hasMoreElements() )
- {
- System.out.println( st.nextToken() );
- }
- }
- } catch ( FileNotFoundException e )
- {
- System.out.println( e.getMessage() );
- }
- scanner.close();
- }
- public static void writeFile( String path, String text, boolean append )
- {
- try{
- FileWriter fileWriter = new FileWriter( path, append );
- BufferedWriter bufferedWriter = new BufferedWriter( fileWriter );
- PrintWriter printWriter = new PrintWriter( bufferedWriter );
- printWriter.println( text );
- printWriter.close();
- }
- catch ( IOException e )
- {
- System.out.println( e );
- }
- }
- public static void Zadanie1()
- {
- Scanner scanner = new Scanner ( System.in );
- System.out.print( "Podaj sciezke: " );
- String path = scanner.nextLine();
- File file = new File( path );
- System.out.println( "Nazwa: " + file.getName() + '\n'
- + "Wielkosc: " + file.length() + '\n'
- + "Ostatnio modyfikowano: " + file.lastModified());
- if ( file.isDirectory() ) {
- System.out.print("Zawartosc: ");
- String[] arr = file.list();
- for (String x : arr)
- System.out.print(x + " ");
- System.out.println();
- }
- }
- public static void Zadanie2()
- {
- Scanner scanner = new Scanner ( System.in );
- System.out.print( "Podaj sciezke: " );
- String path = scanner.nextLine();
- }
- public static void main(String[] args)
- {
- Zadanie1();
- //writeFile( path, "ala ma kota\nkot ma ale\n", true);
- //readFile( path );
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement