Write in file .txt in java











up vote
-2
down vote

favorite












I want write in file .txt and i try this:



save_arq.print("%s;%d:%f;", entry.getValue(), entry.getKey(), result);



I initialize the file this modo:



Scanner file_tf_idf = new Scanner(System.in);
FileWriter arq = new FileWriter("C:\tf_idf.txt");
PrintWriter save_arq = new PrintWriter(arq);


But i have error in save_arq.print.



My complete code:



public class tfidfWeights {

public Map<String, Integer> tfidf(Map<String, Integer> tf_C) throws IOException{

Scanner file_tf_idf = new Scanner(System.in);
FileWriter arq = new FileWriter("C:\tf_idf.txt");
PrintWriter save_arq = new PrintWriter(arq);

Map<String, Integer> idf = new HashMap<String, Integer>();


//Set<Integer> doc_id = new HashSet<Integer>(tf_C.keySet());
Set<Entry<String, Integer>> set = tf_C.entrySet();
Iterator it = set.iterator();

Integer N_total = tf_C.size();

while(it.hasNext()){
//iterar o map
Entry<String, Integer> entry = (Entry)it.next();

double result = 0;
result = Math.log10(N_total/entry.getValue());
save_arq.print("%s;%d:%f;", entry.getValue(), entry.getKey(), result);
System.out.print(result);
}
save_arq.close();
}
}









share|improve this question
























  • What is the error? Please post the full stack trace/a Minimal, Complete, and Verifiable example
    – GBlodgett
    Nov 11 at 3:14








  • 1




    There is no print() method that accepts those arguments. Did you mean to use printf()?
    – GBlodgett
    Nov 11 at 3:15








  • 1




    Also that is not the stacktrace. To see the full stack trace of the errors, re-run Maven with the -e switch.
    – GBlodgett
    Nov 11 at 3:16






  • 1




    Please fix your question so that it is helpful to future visitors -- please post the actual stacktrace. Also are you trying to run non-compilable code? If so, never do that -- get the errors from the compiler and fix those first before trying to run.
    – Hovercraft Full Of Eels
    Nov 11 at 3:21















up vote
-2
down vote

favorite












I want write in file .txt and i try this:



save_arq.print("%s;%d:%f;", entry.getValue(), entry.getKey(), result);



I initialize the file this modo:



Scanner file_tf_idf = new Scanner(System.in);
FileWriter arq = new FileWriter("C:\tf_idf.txt");
PrintWriter save_arq = new PrintWriter(arq);


But i have error in save_arq.print.



My complete code:



public class tfidfWeights {

public Map<String, Integer> tfidf(Map<String, Integer> tf_C) throws IOException{

Scanner file_tf_idf = new Scanner(System.in);
FileWriter arq = new FileWriter("C:\tf_idf.txt");
PrintWriter save_arq = new PrintWriter(arq);

Map<String, Integer> idf = new HashMap<String, Integer>();


//Set<Integer> doc_id = new HashSet<Integer>(tf_C.keySet());
Set<Entry<String, Integer>> set = tf_C.entrySet();
Iterator it = set.iterator();

Integer N_total = tf_C.size();

while(it.hasNext()){
//iterar o map
Entry<String, Integer> entry = (Entry)it.next();

double result = 0;
result = Math.log10(N_total/entry.getValue());
save_arq.print("%s;%d:%f;", entry.getValue(), entry.getKey(), result);
System.out.print(result);
}
save_arq.close();
}
}









share|improve this question
























  • What is the error? Please post the full stack trace/a Minimal, Complete, and Verifiable example
    – GBlodgett
    Nov 11 at 3:14








  • 1




    There is no print() method that accepts those arguments. Did you mean to use printf()?
    – GBlodgett
    Nov 11 at 3:15








  • 1




    Also that is not the stacktrace. To see the full stack trace of the errors, re-run Maven with the -e switch.
    – GBlodgett
    Nov 11 at 3:16






  • 1




    Please fix your question so that it is helpful to future visitors -- please post the actual stacktrace. Also are you trying to run non-compilable code? If so, never do that -- get the errors from the compiler and fix those first before trying to run.
    – Hovercraft Full Of Eels
    Nov 11 at 3:21













up vote
-2
down vote

favorite









up vote
-2
down vote

favorite











I want write in file .txt and i try this:



save_arq.print("%s;%d:%f;", entry.getValue(), entry.getKey(), result);



I initialize the file this modo:



Scanner file_tf_idf = new Scanner(System.in);
FileWriter arq = new FileWriter("C:\tf_idf.txt");
PrintWriter save_arq = new PrintWriter(arq);


But i have error in save_arq.print.



My complete code:



public class tfidfWeights {

public Map<String, Integer> tfidf(Map<String, Integer> tf_C) throws IOException{

Scanner file_tf_idf = new Scanner(System.in);
FileWriter arq = new FileWriter("C:\tf_idf.txt");
PrintWriter save_arq = new PrintWriter(arq);

Map<String, Integer> idf = new HashMap<String, Integer>();


//Set<Integer> doc_id = new HashSet<Integer>(tf_C.keySet());
Set<Entry<String, Integer>> set = tf_C.entrySet();
Iterator it = set.iterator();

Integer N_total = tf_C.size();

while(it.hasNext()){
//iterar o map
Entry<String, Integer> entry = (Entry)it.next();

double result = 0;
result = Math.log10(N_total/entry.getValue());
save_arq.print("%s;%d:%f;", entry.getValue(), entry.getKey(), result);
System.out.print(result);
}
save_arq.close();
}
}









share|improve this question















I want write in file .txt and i try this:



save_arq.print("%s;%d:%f;", entry.getValue(), entry.getKey(), result);



I initialize the file this modo:



Scanner file_tf_idf = new Scanner(System.in);
FileWriter arq = new FileWriter("C:\tf_idf.txt");
PrintWriter save_arq = new PrintWriter(arq);


But i have error in save_arq.print.



My complete code:



public class tfidfWeights {

public Map<String, Integer> tfidf(Map<String, Integer> tf_C) throws IOException{

Scanner file_tf_idf = new Scanner(System.in);
FileWriter arq = new FileWriter("C:\tf_idf.txt");
PrintWriter save_arq = new PrintWriter(arq);

Map<String, Integer> idf = new HashMap<String, Integer>();


//Set<Integer> doc_id = new HashSet<Integer>(tf_C.keySet());
Set<Entry<String, Integer>> set = tf_C.entrySet();
Iterator it = set.iterator();

Integer N_total = tf_C.size();

while(it.hasNext()){
//iterar o map
Entry<String, Integer> entry = (Entry)it.next();

double result = 0;
result = Math.log10(N_total/entry.getValue());
save_arq.print("%s;%d:%f;", entry.getValue(), entry.getKey(), result);
System.out.print(result);
}
save_arq.close();
}
}






java file mod-rewrite






share|improve this question















share|improve this question













share|improve this question




share|improve this question








edited Nov 11 at 3:19









Hovercraft Full Of Eels

260k20209316




260k20209316










asked Nov 11 at 3:13









Elaine

118




118












  • What is the error? Please post the full stack trace/a Minimal, Complete, and Verifiable example
    – GBlodgett
    Nov 11 at 3:14








  • 1




    There is no print() method that accepts those arguments. Did you mean to use printf()?
    – GBlodgett
    Nov 11 at 3:15








  • 1




    Also that is not the stacktrace. To see the full stack trace of the errors, re-run Maven with the -e switch.
    – GBlodgett
    Nov 11 at 3:16






  • 1




    Please fix your question so that it is helpful to future visitors -- please post the actual stacktrace. Also are you trying to run non-compilable code? If so, never do that -- get the errors from the compiler and fix those first before trying to run.
    – Hovercraft Full Of Eels
    Nov 11 at 3:21


















  • What is the error? Please post the full stack trace/a Minimal, Complete, and Verifiable example
    – GBlodgett
    Nov 11 at 3:14








  • 1




    There is no print() method that accepts those arguments. Did you mean to use printf()?
    – GBlodgett
    Nov 11 at 3:15








  • 1




    Also that is not the stacktrace. To see the full stack trace of the errors, re-run Maven with the -e switch.
    – GBlodgett
    Nov 11 at 3:16






  • 1




    Please fix your question so that it is helpful to future visitors -- please post the actual stacktrace. Also are you trying to run non-compilable code? If so, never do that -- get the errors from the compiler and fix those first before trying to run.
    – Hovercraft Full Of Eels
    Nov 11 at 3:21
















What is the error? Please post the full stack trace/a Minimal, Complete, and Verifiable example
– GBlodgett
Nov 11 at 3:14






What is the error? Please post the full stack trace/a Minimal, Complete, and Verifiable example
– GBlodgett
Nov 11 at 3:14






1




1




There is no print() method that accepts those arguments. Did you mean to use printf()?
– GBlodgett
Nov 11 at 3:15






There is no print() method that accepts those arguments. Did you mean to use printf()?
– GBlodgett
Nov 11 at 3:15






1




1




Also that is not the stacktrace. To see the full stack trace of the errors, re-run Maven with the -e switch.
– GBlodgett
Nov 11 at 3:16




Also that is not the stacktrace. To see the full stack trace of the errors, re-run Maven with the -e switch.
– GBlodgett
Nov 11 at 3:16




1




1




Please fix your question so that it is helpful to future visitors -- please post the actual stacktrace. Also are you trying to run non-compilable code? If so, never do that -- get the errors from the compiler and fix those first before trying to run.
– Hovercraft Full Of Eels
Nov 11 at 3:21




Please fix your question so that it is helpful to future visitors -- please post the actual stacktrace. Also are you trying to run non-compilable code? If so, never do that -- get the errors from the compiler and fix those first before trying to run.
– Hovercraft Full Of Eels
Nov 11 at 3:21












1 Answer
1






active

oldest

votes

















up vote
2
down vote













There is no print method in the PrintWriter class that accepts those arguments. I'm assuming you wanted to use the printf() method, which accepts:



printf(String format, Object... args)


So your code would be:



save_arq.printf("%s;%d:%f;", entry.getValue(), entry.getKey(), result);





share|improve this answer





















    Your Answer






    StackExchange.ifUsing("editor", function () {
    StackExchange.using("externalEditor", function () {
    StackExchange.using("snippets", function () {
    StackExchange.snippets.init();
    });
    });
    }, "code-snippets");

    StackExchange.ready(function() {
    var channelOptions = {
    tags: "".split(" "),
    id: "1"
    };
    initTagRenderer("".split(" "), "".split(" "), channelOptions);

    StackExchange.using("externalEditor", function() {
    // Have to fire editor after snippets, if snippets enabled
    if (StackExchange.settings.snippets.snippetsEnabled) {
    StackExchange.using("snippets", function() {
    createEditor();
    });
    }
    else {
    createEditor();
    }
    });

    function createEditor() {
    StackExchange.prepareEditor({
    heartbeatType: 'answer',
    convertImagesToLinks: true,
    noModals: true,
    showLowRepImageUploadWarning: true,
    reputationToPostImages: 10,
    bindNavPrevention: true,
    postfix: "",
    imageUploader: {
    brandingHtml: "Powered by u003ca class="icon-imgur-white" href="https://imgur.com/"u003eu003c/au003e",
    contentPolicyHtml: "User contributions licensed under u003ca href="https://creativecommons.org/licenses/by-sa/3.0/"u003ecc by-sa 3.0 with attribution requiredu003c/au003e u003ca href="https://stackoverflow.com/legal/content-policy"u003e(content policy)u003c/au003e",
    allowUrls: true
    },
    onDemand: true,
    discardSelector: ".discard-answer"
    ,immediatelyShowMarkdownHelp:true
    });


    }
    });














     

    draft saved


    draft discarded


















    StackExchange.ready(
    function () {
    StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2fstackoverflow.com%2fquestions%2f53245538%2fwrite-in-file-txt-in-java%23new-answer', 'question_page');
    }
    );

    Post as a guest















    Required, but never shown

























    1 Answer
    1






    active

    oldest

    votes








    1 Answer
    1






    active

    oldest

    votes









    active

    oldest

    votes






    active

    oldest

    votes








    up vote
    2
    down vote













    There is no print method in the PrintWriter class that accepts those arguments. I'm assuming you wanted to use the printf() method, which accepts:



    printf(String format, Object... args)


    So your code would be:



    save_arq.printf("%s;%d:%f;", entry.getValue(), entry.getKey(), result);





    share|improve this answer

























      up vote
      2
      down vote













      There is no print method in the PrintWriter class that accepts those arguments. I'm assuming you wanted to use the printf() method, which accepts:



      printf(String format, Object... args)


      So your code would be:



      save_arq.printf("%s;%d:%f;", entry.getValue(), entry.getKey(), result);





      share|improve this answer























        up vote
        2
        down vote










        up vote
        2
        down vote









        There is no print method in the PrintWriter class that accepts those arguments. I'm assuming you wanted to use the printf() method, which accepts:



        printf(String format, Object... args)


        So your code would be:



        save_arq.printf("%s;%d:%f;", entry.getValue(), entry.getKey(), result);





        share|improve this answer












        There is no print method in the PrintWriter class that accepts those arguments. I'm assuming you wanted to use the printf() method, which accepts:



        printf(String format, Object... args)


        So your code would be:



        save_arq.printf("%s;%d:%f;", entry.getValue(), entry.getKey(), result);






        share|improve this answer












        share|improve this answer



        share|improve this answer










        answered Nov 11 at 3:20









        GBlodgett

        7,14441329




        7,14441329






























             

            draft saved


            draft discarded



















































             


            draft saved


            draft discarded














            StackExchange.ready(
            function () {
            StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2fstackoverflow.com%2fquestions%2f53245538%2fwrite-in-file-txt-in-java%23new-answer', 'question_page');
            }
            );

            Post as a guest















            Required, but never shown





















































            Required, but never shown














            Required, but never shown












            Required, but never shown







            Required, but never shown

































            Required, but never shown














            Required, but never shown












            Required, but never shown







            Required, but never shown







            Popular posts from this blog

            Xamarin.iOS Cant Deploy on Iphone

            Glorious Revolution

            Dulmage-Mendelsohn matrix decomposition in Python