質問編集履歴

1

調べてみると、ソケット接続にBufferedInputStreamは向いていないとのことなので、InputStreamを使用するよう変更、それに伴いwhile文も変更しました。

2020/07/17 06:02

投稿

ShiroKuro1
ShiroKuro1

スコア1

test CHANGED
File without changes
test CHANGED
@@ -66,7 +66,7 @@
66
66
 
67
67
 
68
68
 
69
- import java.io.BufferedInputStream;
69
+ import java.io.InputStream;
70
70
 
71
71
  import java.io.BufferedWriter;
72
72
 
@@ -216,15 +216,19 @@
216
216
 
217
217
  private void StartPick() {
218
218
 
219
- try (BufferedInputStream bufferedInputStream =
220
-
221
- new BufferedInputStream(btSocket.getInputStream());
219
+ try (InputStream inputStream = btSocket.getInputStream();
220
+
222
-
221
+ OutputStream outputStream =
222
+
223
- OutputStream outputStream = openFileOutput(fileName, Context.MODE_PRIVATE);
223
+ openFileOutput(fileName, Context.MODE_PRIVATE);
224
+
224
-
225
+ OutputStreamWriter outputStreamWriter =
226
+
225
- OutputStreamWriter outputStreamWriter = new OutputStreamWriter(outputStream, "UTF-8");
227
+ new OutputStreamWriter(outputStream, "UTF-8");
228
+
226
-
229
+ BufferedWriter bufferedWriter =
230
+
227
- BufferedWriter bufferedWriter = new BufferedWriter(outputStreamWriter)) {
231
+ new BufferedWriter(outputStreamWriter)) {
228
232
 
229
233
 
230
234
 
@@ -238,12 +242,22 @@
238
242
 
239
243
 
240
244
 
245
+ while (true) {
246
+
241
- while ((len = bufferedInputStream.read(buffer)) != -1) {
247
+ int len = inputStream.read(buffer);
248
+
249
+ if (len == -1) {
250
+
251
+ break;
252
+
253
+ }
242
254
 
243
255
  outputStream.write(buffer, 0, len);
244
256
 
245
257
  }
246
258
 
259
+
260
+
247
261
  String readData = outputStream.toString();
248
262
 
249
263
  if (readData.trim() != null && !readData.trim().equals("")) {