Bestimmte Anzahl von Bytes lesen und als string ausgeben?

Ich war etwas eingerostet, hab länger kein java mehr programmiert aber nun gehts wieder 😉

evtl hilft das jemand:

Java:
		InputStream is = new BufferedInputStream(new FileInputStream("C:\\x.txt"));
		
		//Anzahl bytes
		byte[] buf = new byte[30];
		
		int read = 0;
		
		while(true) {
			
            read = is.read(buf);
            
            if (read == -1) 
                break;
           
            //new String(buf).trim()
            
		}
		
		is.close();
 
>evtl hilft das jemand:

Was willst du denn machen?
in.read() liest ein byte und stopft ihn in einen int...
in.read(byte[]) liesx x byte in ein byte Array

oder was ist deine Frage?

EDIT:
noch ein bissel Code
Java:
File file = new File("blub");
BufferedInputStream bis = new BufferedInputStream(new FileInputStream(file));
int i;
int count = 0;
while((i = bis.read()) != -1) {
	System.out.println("byte@: " + count++ +" is " +i);
}
bis.close();
 
Zuletzt bearbeitet:

Zurück
Oben