How do I for my application gets in the options to open a txt file

Asked

Viewed 34 times

1

I would like to know how I do so that my application comes to is in the list which options to open text file, my application is small only to read and edit txt file for me to train programming, user will click on a txt file and will open directly in my APK application only I could not find the code to do this if anyone can help me I thank you.

1 answer

-1

Buddy I picked up an example comic

Manipulative.java.:

package gomes.fernando.robson;

 import java.io.BufferedReader;
 import java.io.BufferedWriter;
 import java.io.FileReader;
 import java.io.FileWriter;
 import java.io.IOException;
 import java.util.Scanner;

public class ManipuladorArquivo 
{

public static void leitor(String path) throws IOException {
    BufferedReader buffRead = new BufferedReader(new FileReader(path));
    String linha = "";
    while (true) {
        if (linha != null) {
            System.out.println(linha);

        } else
            break;
        linha = buffRead.readLine();
    }
    buffRead.close();
}

public static void escritor(String path) throws IOException {
    BufferedWriter buffWrite = new BufferedWriter(new FileWriter(path));
    String linha = "";
    Scanner in = new Scanner(System.in);
    System.out.println("Escreva algo: ");
    linha = in.nextLine();
    buffWrite.append(linha + "\n");
    buffWrite.close();
}

}

Main java.:

package gomes.fernando.robson;

import java.io.IOException;

public class Principal {

public static void main(String args[]) throws IOException {
    String path = "/tmp/file.txt";

    ManipuladorArquivo.escritor(path);
    ManipuladorArquivo.leitor(path);
}

}

Well the main class will use the Manipulative class.java which has the function to read and write the file. Good you just treat the reading with the visual part, xml ...

Would you like a more detailed explanation of the above code? Original article: https://www.devmedia.com.br/leitura-e-escrita-de-arquivos-de-texto-em-java/25529

  • Sorry if I don’t clarify, what I was wanting is not the code to read and write was how to leave my application in the list, in the option to read text file for when user press a text file my application appearing the options to open with it, but thank you for the encouragement thank you even more if you can help me at this particular point.

Browser other questions tagged

You are not signed in. Login or sign up in order to post.