Código de Java - Lee un archivo

1.0
estrellaestrellaestrellaestrellaestrella(1)

Actualizado el 21 de Noviembre del 2017 (Publicado el 19 de Octubre del 2017)gráfica de visualizaciones de la versión: 1.0
2.199 visualizaciones desde el 19 de Octubre del 2017
estrellaestrellaestrellaestrellaestrella
estrellaestrellaestrellaestrella
estrellaestrellaestrella
estrellaestrella
estrella

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
import java.io.*;
 
class ReadBinaryFile
{
    public static void main(String[] args)
    {
        // The name of the file to open.
        String fileName = "file.txt";
 
        FileInputStream inputStream = null;
 
        try
        {
            // Use this for reading the data.
            byte[] buffer = new byte[1000];
 
            inputStream = new FileInputStream(fileName);
 
            // read fills buffer with data and returns
            // the number of bytes read (which of course
            // may be less than the buffer size, but
            // it will never be more).
            int total = 0;
            int nRead = 0;
 
            while ((nRead = inputStream.read(buffer)) != -1)
            {
                // Convert to String so we can display it.
                // Of course you wouldn't want to do this with
                // a 'real' binary file.
                System.out.println(new String(buffer));
                total += nRead;
            }
 
            System.out.println("Read " + total + " bytes");
        }
        catch (FileNotFoundException ex)
        {
            System.out.println("Unable to open file '" + fileName + "'");
        }
        catch (IOException ex)
        {
            System.out.println("Error reading file '" + fileName + "'");
            // Or we could just do this:
            // ex.printStackTrace();
        }
        finally
        {
            // Always close files.
            try
            {
                if (inputStream != null)
                {
                    inputStream.close();
                }
            }
            catch (IOException e)
            {
            }
        }
    }
}



Comentarios sobre la versión: 1.0 (1)

Gino
21 de Enero del 2022
estrellaestrellaestrellaestrellaestrella
for (int factor = 1; factor <= number; factor++)
Responder

Comentar la versión: 1.0

Nombre
Correo (no se visualiza en la web)
Valoración
Comentarios...
CerrarCerrar
CerrarCerrar
Cerrar

Tienes que ser un usuario registrado para poder insertar imágenes, archivos y/o videos.

Puedes registrarte o validarte desde aquí.

Codigo
Negrita
Subrayado
Tachado
Cursiva
Insertar enlace
Imagen externa
Emoticon
Tabular
Centrar
Titulo
Linea
Disminuir
Aumentar
Vista preliminar
sonreir
dientes
lengua
guiño
enfadado
confundido
llorar
avergonzado
sorprendido
triste
sol
estrella
jarra
camara
taza de cafe
email
beso
bombilla
amor
mal
bien
Es necesario revisar y aceptar las políticas de privacidad

http://lwp-l.com/s4277