Etant relativement débutant dans Android Studio, je me permets de vous soumettre mon problème : je voudrais lire le contenu d'un fichier texte se trouvant dans mon réseau local. Android Studio ne retourne aucune erreur, mais ne retourne aucune valeur contenue dans mon fichier texte_a_lire.txt. J'utilise la bibliothèque jcifs-1.3.19.jar.
Merci d'avance de votre aide.

Voici mon code :

Code : Sélectionner tout - Visualiser dans une fenêtre à part
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
package com.example.lire_fichier_txt;
 
import android.app.Activity;
import android.os.Bundle;
import android.util.Log;
import android.widget.TextView;
 
 
import androidx.appcompat.app.AppCompatActivity;
 
import java.io.BufferedReader;
import java.io.File;
import java.io.FileNotFoundException;
import java.io.FileOutputStream;
import java.io.FileReader;
import java.io.IOException;
import java.net.MalformedURLException;
 
//import jcifs.config.PropertyConfiguration;
//import jcifs.context.BaseContext;
import jcifs.Config;
import jcifs.smb.*;
//import jcifs.CIFSContext;
import jcifs.smb.NtlmPasswordAuthentication;
import jcifs.smb.SmbException;
import jcifs.smb.SmbFile;
import jcifs.smb.SmbFileOutputStream;
import jcifs.smb.*;
 
 
 
public class MainActivity extends AppCompatActivity {
 
    TextView contenufichier;
 
    @Override
    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.activity_main);
 
        // Initialisation des variables
        contenufichier = findViewById(R.id.contenu);
 
        String yourPeerPassword = "*****";
        String yourPeerName = "*****";
        String yourPeerIP = "192.168.10.55";
        String remoteFile = "texte_a_lire.txt";
        String smbfilepath = "smb://" + yourPeerIP + "/Documents/mesdocs/suspens/" + remoteFile;
 
        Config.setProperty( "jcifs.netbios.wins", "192.168.10.55" );
        NtlmPasswordAuthentication auth = new NtlmPasswordAuthentication(null, yourPeerName, yourPeerPassword);
 
        SmbFile smbFile = null;
        try {
            smbFile = new SmbFile(smbfilepath, auth);
        } catch (MalformedURLException e) {
            e.printStackTrace();
        }
 
        String nameoffile = smbFile.getName();
        String pathoffile = smbFile.getPath();
 
 
        //jusque-là tout va bien
        String contenufile = new String();
 
        try {
            BufferedReader br = new BufferedReader(new FileReader(pathoffile));
            String line;
 
            while ((line = br.readLine()) != null) {
                contenufile.contains(line);
                contenufile.contains("\n");
            }
            br.close();
        }
        catch (IOException e) {
 
        }
 
        String infosfichier;
 
       // infosfichier = contenufile;
        contenufichier.setText(contenufile);
 
    }
 
}