עבור לתוכן
View in the app

A better way to browse. Learn more.

HWzone

A full-screen app on your home screen with push notifications, badges and more.

To install this app on iOS and iPadOS
  1. Tap the Share icon in Safari
  2. Scroll the menu and tap Add to Home Screen.
  3. Tap Add in the top-right corner.
To install this app on Android
  1. Tap the 3-dot menu (⋮) in the top-right corner of the browser.
  2. Tap Add to Home screen or Install app.
  3. Confirm by tapping Install.

בעיה בקריאה מקובץ עם FileInputStream ב Java

Featured Replies

פורסם

שלום,

אני מנסה לקרוא מערך של ביטים מקובץ ב Java בעזרת הספריה FileInputStream הבעיה היא שעבור ערכים מסויימים הספריה ממירה אותם מ Hex ל Dec בצורה לא נכונה לדוגמא אם בקובץ יש את הביתים הבאים:

00 00 15 A2

הספריה קוראת אותם לתוך המערך בגודל 4 באופן הבא

[ 0, 0, 21, 94- ]

ההמרה של 15 היא באמת נכונה ו 0x15=21 אבל למה למה הוא ממיר A2 ל 94-?

עוד דוגמא

00 FF 03 00

אני מקבל מערך שמכיל את המספרים הבאים

[ 0, 0, 3, 1- ]

הצורה שבה אני קורא מהקובץ


byte[] signa = new byte[4];
File file = new File(fileName);;
FileInputStream fis = new FileInputStream(file);

fis.read(signa, 0, 4);

למישהו יש מושג למה זה קורה???

תודה

פורסם

Byte בג'אווה הוא טיפוס signed, מה שאומר שהטווח שלו הוא 128- עד 127, כשהביט העליון ביותר בייצוג הבינארי של המספר מייצג את הסימן. כלומר, אם הביט העליון הוא 0 אז המספר חיובי (או 0), אחרת המספר שלילי.

פורסם
  • מחבר

אוקי מצאתי פתרון לבעיה

int a = byte & 0xFF;

פותר את הבעיה

תודה רבה

אפשר לנעול

פורסם

ניסית להשתמש ב ByteArrayInputStream

ארכיון

דיון זה הועבר לארכיון ולא ניתן להוסיף בו תגובות חדשות.

דיונים חדשים

Configure browser push notifications

Chrome (Android)
  1. Tap the lock icon next to the address bar.
  2. Tap Permissions → Notifications.
  3. Adjust your preference.
Chrome (Desktop)
  1. Click the padlock icon in the address bar.
  2. Select Site settings.
  3. Find Notifications and adjust your preference.