Advertisement
TrodelHD

Untitled

Mar 14th, 2018
88
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 2.89 KB | None | 0 0
  1. package main;
  2.  
  3. import java.io.File;
  4. import java.io.FileNotFoundException;
  5. import java.io.IOException;
  6. import java.util.ArrayList;
  7. import java.util.Formatter;
  8. import java.util.Properties;
  9. import java.util.Scanner;
  10.  
  11. import javax.swing.JFrame;
  12.  
  13.  
  14. public class main{
  15.  
  16.  
  17. public static void main(String args[]) throws InterruptedException {
  18. @SuppressWarnings("unused")
  19. JFrame frame = new frame();
  20.  
  21. File a= new File(args[0]);
  22. System.out.println(a.getName());
  23.  
  24. createdata();
  25.  
  26. }
  27. private static String benutzer = new Properties(System.getProperties()).getProperty("user.name");
  28. private static String datapath = "C://Users/"+benutzer+"/Documents/"+benutzer+"_WurzelZieher";
  29. private static String filename = "BenchmarkPoins.txt";
  30. public static void createdata(){
  31.  
  32. File file = new File(datapath+"/"+filename);
  33. File dir = new File(datapath);
  34. if(!dir.exists()){
  35. dir.mkdirs();
  36. }
  37. if(!file.exists()){
  38. try {
  39. file.createNewFile();
  40. } catch (IOException e) {
  41. e.printStackTrace();
  42. }
  43. }else{
  44.  
  45. }
  46.  
  47.  
  48. }
  49. @SuppressWarnings("resource")
  50. public static void addData(int value){
  51. if(value==0){
  52. return;
  53. }
  54. Formatter x = null;
  55. ArrayList<Integer> re = null;
  56. re = new ArrayList<Integer>();
  57. Scanner s = null;
  58. File file = new File(datapath+"/"+filename);
  59. if(!file.exists()){
  60. createdata();
  61. }
  62.  
  63. try {
  64. s=new Scanner(file);
  65. } catch (FileNotFoundException e) {
  66. return;
  67. }
  68. if(!s.hasNext()){
  69. try {
  70. x = new Formatter(file);
  71. x.format("%s ",value);
  72. x.close();
  73. } catch (FileNotFoundException e) {
  74. }
  75. return;
  76. }
  77. boolean run = true;
  78. while(run){
  79. if(s.hasNext()){
  80. re.add(s.nextInt());
  81. }else{
  82. run = false;
  83. }
  84. }
  85.  
  86. re.add(value);
  87. try {
  88. x = new Formatter(file);
  89. } catch (FileNotFoundException e) {
  90. return;
  91. }
  92. for(int i = 0;i<re.size();i++){
  93. x.format("%s ",re.get(i));
  94. }
  95.  
  96. x.close();
  97.  
  98. return;
  99. }
  100. @SuppressWarnings("resource")
  101. public static ArrayList<Integer> getData(){
  102. ArrayList<Integer> re = null;
  103. re = new ArrayList<Integer>();
  104. Scanner s = null;
  105. File file = new File(datapath+"/"+filename);
  106. if(!file.exists()){
  107. return null;
  108. }
  109. if(!file.exists()){
  110. return null;
  111. }
  112. try {
  113. s=new Scanner(file);
  114. } catch (FileNotFoundException e) {
  115. return null;
  116. }
  117.  
  118. if(!s.hasNext()){
  119. re.add(0);
  120. return re;
  121. }
  122. boolean run = true;
  123. while(run){
  124. if(s.hasNext()){
  125. re.add(s.nextInt());
  126. }else{
  127. run = false;
  128. }
  129. }
  130.  
  131. return re;
  132. }
  133. public static void removeData(){
  134. Formatter x = null;
  135. File file = new File(datapath+"/"+filename);
  136. if(!file.exists()){
  137. return;
  138. }
  139. try {
  140. x = new Formatter(file);
  141. x.format("","");
  142. x.close();
  143. } catch (FileNotFoundException e) {
  144. return;
  145. }
  146. return;
  147. }
  148.  
  149. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement