Plugin Help Problem with delete with files string

Discussion in 'Plugin Help/Development/Requests' started by tomecki1, Jul 4, 2016.

Thread Status:
Not open for further replies.
  1. Hello,
    I have file with reports players. I want delete lines with this file. I don't know. What method?
    Please help me ;)
     
  2. Offline

    timtower Administrator Administrator Moderator

    @tomecki1 What kind of storage method are you using?
    Yaml? Fike writer?
     
  3. .txt
     
  4. Offline

    I Al Istannen

    @tomecki1
    So a file writer?
    May need to read the whole file and then save the ones you need.
    Or copy the file to a tmp file, skipping the lines you want to remove and then deleting the original and renaming the tmp file.
     
  5. But I want to make the player from the game he could remove the first 3 lines and then what is next stored in advance by 3 lines to the top
     
  6. Offline

    I Al Istannen

    @tomecki1
    Could you rephrase that? I didn't understand you :/
     
  7. Ehhhh...
    I have a command / remove
    He wants to after using this command from the File [...]. Txt have pulled out the first 3 lines of text, and these lines that are behind those moved to the first 3.
    Do you understand?
    Imaging:
    It is my text:
    Show Spoiler

    sender: tomecki1
    reported: jacek
    Reason: bla bla bla
    sender: jacek
    reported: tomecki
    Reason: bla bla bla
    sender: aga
    reported: adkvd
    Reason: bla bla bla


    And now:

    Show Spoiler

    sender: tomecki1 // delete
    reported: jacek // delete
    Reason: bla bla bla // delete
    sender: jacek
    reported: tomecki
    Reason: bla bla bla
    sender: aga
    reported: adkvd
    Reason: bla bla bla


    And I have it:

    Show Spoiler

    sender: jacek
    reported: tomecki
    Reason: bla bla bla
    sender: aga
    reported: adkvd
    Reason: bla bla bla

    Do you understand? :D
     
  8. Offline

    I Al Istannen

    @tomecki1
    Yes ;)
    I would read the file using a BufferedReader, skip the first 3 lines and write the rest to another temporary file. Then delete the original and move and rename the temporary one to the original.

    Or read all the contents in a List (Using Files.readAllLines or a BufferedReader), remove the first 3 and write it to the file again.
     
  9. Good :D
    oh my god, it is very complicated...
    massacre...

    and I have no further to look for information on the net ...
     
  10. Offline

    I Al Istannen

    @tomecki1
    Here, or google "java delete some lines from file".
     
  11. Thanks :D
    I'll try to find something...

    @I Al Istannen
    :D
    It is my code:
    Code:
    public boolean onCommand(CommandSender sender, Command cmd, String label, String[] args) {
         if (cmd.getName().equalsIgnoreCase("usunraport")) {
           
           File file = new File("zgloszenia.txt");
           StringBuilder sb = new StringBuilder();
           try (BufferedReader br = new BufferedReader(new FileReader("zgloszenia.txt"))) {
             String line;
             
             while ((line = br.readLine()) != null) {
               sender.sendMessage(line);
             }
    
           } catch (IOException e) {
             sender.sendMessage(ChatColor.RED + "Nie ma żadnych raportów!");
             sender.sendMessage(" ");
           
         }
           String[] lines = {};
           for (String emm : lines) {
             Writer.writeFile("zgloszenia.txt", emm);
           }
         }
         return true;
       }
    
    and I'm reading a file and do not know what to do removed and overwrite...
    Help me please.

    EDIT by Moderator: merged posts, please use the edit button instead of double posting.
     
    Last edited by a moderator: Jul 5, 2016
  12. Help me please!
    how to search the many themes and nothing!
     
  13. Offline

    I Al Istannen

    @tomecki1
    I don't really understand your english, which I am sorry for :/

    But currently you only read the file. Add a counter, which checks how many lines are written. If the counter is <= 3, continue. Else save the line in a String list (List<String>). Later just use Files.write to save it to the file again.

    You can read about reading and writing here.
     
  14. ;(
    @I Al Istannen
    I tried in different ways

    You are prompted for me?

    I did so, but it does not work:
    Show Spoiler

    Code:
    if (cmd.getName().equalsIgnoreCase("usunraport")) {
                 
           try (BufferedReader br = new BufferedReader(new FileReader("zgloszenia.txt"))) {
             String line;
             while ((line = br.readLine()) != null) {
               plik.add(line);
             }
             plik.remove(0);
             plik.remove(1);
             plik.remove(2);
             plik.remove(3);
             String line2;
             for(int i=0; i<plik.size(); i++){
             line2 = plik.get(i);
               sender.sendMessage(line2);
               Writer.writeFile("zmiany.txt", line2);
             }
         
           
           } catch (IOException e) {
             sender.sendMessage(ChatColor.RED + "Nie ma żadnych raportów!");
             sender.sendMessage(" ");
         
         }
         }
    


    I think that arraylist can not be...

    but I do not know how...

    I don't know!!! ;(
     
  15. Just going to put this in here, if you did want to use YAML which is nicer to look at for sure just is a little syntax sensitive that is always an option and you can just do set(path, "") to remove a section. There are many utilities in the resources section that allow you to make your own YAML file with little code.
     
Thread Status:
Not open for further replies.

Share This Page