Advertisement
Guest User

Untitled

a guest
Dec 9th, 2019
96
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 2.39 KB | None | 0 0
  1. import java.io.*;
  2. import java.util.List;
  3. import java.util.Scanner;
  4. import java.util.StringTokenizer;
  5.  
  6.  
  7. public class Main
  8. {
  9. public static void readFile( String path )
  10. {
  11. Scanner scanner = null;
  12. File file = new File( path );
  13. StringTokenizer st;
  14. try {
  15. scanner = new Scanner(file);
  16. while (scanner.hasNextLine() )
  17. {
  18. //System.out.println( scanner.nextLine() );
  19. st = new StringTokenizer( scanner.nextLine(), " " );
  20. while ( st.hasMoreElements() )
  21. {
  22. System.out.println( st.nextToken() );
  23. }
  24. }
  25.  
  26. } catch ( FileNotFoundException e )
  27. {
  28. System.out.println( e.getMessage() );
  29. }
  30.  
  31. scanner.close();
  32.  
  33. }
  34.  
  35. public static void writeFile( String path, String text, boolean append )
  36. {
  37. try{
  38. FileWriter fileWriter = new FileWriter( path, append );
  39. BufferedWriter bufferedWriter = new BufferedWriter( fileWriter );
  40. PrintWriter printWriter = new PrintWriter( bufferedWriter );
  41. printWriter.println( text );
  42. printWriter.close();
  43. }
  44. catch ( IOException e )
  45. {
  46. System.out.println( e );
  47. }
  48. }
  49.  
  50. public static void Zadanie1()
  51. {
  52. Scanner scanner = new Scanner ( System.in );
  53.  
  54. System.out.print( "Podaj sciezke: " );
  55.  
  56. String path = scanner.nextLine();
  57.  
  58. File file = new File( path );
  59.  
  60. System.out.println( "Nazwa: " + file.getName() + '\n'
  61. + "Wielkosc: " + file.length() + '\n'
  62. + "Ostatnio modyfikowano: " + file.lastModified());
  63.  
  64. if ( file.isDirectory() ) {
  65. System.out.print("Zawartosc: ");
  66. String[] arr = file.list();
  67.  
  68. for (String x : arr)
  69. System.out.print(x + " ");
  70.  
  71. System.out.println();
  72. }
  73. }
  74.  
  75. public static void Zadanie2()
  76. {
  77.  
  78. Scanner scanner = new Scanner ( System.in );
  79.  
  80. System.out.print( "Podaj sciezke: " );
  81.  
  82. String path = scanner.nextLine();
  83. }
  84.  
  85. public static void main(String[] args)
  86. {
  87.  
  88. Zadanie1();
  89.  
  90.  
  91. //writeFile( path, "ala ma kota\nkot ma ale\n", true);
  92.  
  93. //readFile( path );
  94. }
  95. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement