Advertisement
Guest User

Untitled

a guest
Jan 21st, 2018
68
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 2.35 KB | None | 0 0
  1. package javaapplication21;
  2.  
  3. import java.io.IOException;
  4. import java.io.RandomAccessFile;
  5.  
  6. /**
  7. *
  8. * @author MDLejTeCole
  9. */
  10. public class JavaApplication21
  11. {
  12. public static void emerytura(String text) throws IOException
  13. {
  14. RandomAccessFile raw = null;
  15. String gw="";
  16. long wskaznik2;
  17. char plec;
  18. String imie ="";
  19. String nazwisko;
  20. int wiek;
  21. try
  22. {
  23. raw = new RandomAccessFile(text,"rw");
  24. raw.writeUTF("Mam");
  25. raw.writeUTF("Java");
  26. raw.writeChar('K');
  27. raw.writeInt(35);
  28.  
  29. raw.writeUTF("Wak");
  30. raw.writeUTF("Paw");
  31. raw.writeChar('K');
  32. raw.writeInt(59);
  33.  
  34. raw.writeUTF("Draw");
  35. raw.writeUTF("Ciach");
  36. raw.writeChar('M');
  37. raw.writeInt(59);
  38.  
  39. raw.writeUTF("Mam");
  40. raw.writeUTF("Java");
  41. raw.writeChar('M');
  42. raw.writeInt(54);
  43.  
  44. raw.writeUTF("Zaam");
  45. raw.writeUTF("Wa");
  46. raw.writeChar('K');
  47. raw.writeInt(38);
  48.  
  49. //gw = raw.readLine();
  50. while(true)
  51. {
  52. //System.out.print("Siema");
  53. imie = raw.readUTF();
  54. nazwisko = raw.readUTF();
  55. plec = raw.readChar();
  56. wskaznik2 = raw.getFilePointer();
  57. wiek = raw.readInt();
  58.  
  59. if(plec == 'K')
  60. {
  61. raw.seek(wskaznik2);
  62. wiek = 60 - wiek;
  63. }
  64. if(plec == 'M')
  65. {
  66. raw.seek(wskaznik2);
  67. wiek = 65 - wiek;
  68. }
  69. //gw = raw.readLine();
  70. }
  71. }
  72. catch(IOException ex)
  73. {
  74. System.out.print("bląd");
  75. ex.getStackTrace();
  76. }
  77. finally
  78. {
  79. if (raw != null)
  80. {
  81. raw.close();
  82. }
  83. }
  84. }
  85. /**
  86. * @param args the command line arguments
  87. */
  88. public static void main(String[] args) throws IOException{
  89. emerytura("siemaa.txt");
  90. // TODO code application logic here
  91. }
  92.  
  93. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement