質問編集履歴

5

変換前CSVファイルの項目が1つ抜けていたため修正

2023/04/20 05:57

投稿

moo1211
moo1211

スコア3

test CHANGED
File without changes
test CHANGED
@@ -8,8 +8,8 @@
8
8
 
9
9
  ```
10
10
  【変換前CSVファイル】
11
- B,2023,1,22,1234567,12345,"山田たろう           "
11
+ B,2023,1,22,1,1234567,12345,"山田たろう           "
12
- B,2023,1,22,123456,1234,"佐藤けん    "
12
+ B,2023,1,22,1,123456,1234,"佐藤けん    "
13
13
  ```
14
14
 
15
15
  上記のようなCSVファイルをJavaで読み込み、テキストファイルに変換するプログラムを作っています。

4

itemsのインデックス連番を0からに修正

2023/04/20 05:25

投稿

moo1211
moo1211

スコア3

test CHANGED
File without changes
test CHANGED
@@ -91,14 +91,14 @@
91
91
 
92
92
  final String[] items = line.replace("\"", "").split(",");
93
93
  //行データを出力ファイルへ書き出す。
94
- os.write(String.format("%-100s", items[1]).getBytes(enc), 0, 1);
94
+ os.write(String.format("%-100s", items[0]).getBytes(enc), 0, 1);
95
- os.write(String.format("%04d", Integer.parseInt(items[2])).getBytes(enc));
95
+ os.write(String.format("%04d", Integer.parseInt(items[1])).getBytes(enc));
96
+ os.write(String.format("%02d", Integer.parseInt(items[2])).getBytes(enc));
96
97
  os.write(String.format("%02d", Integer.parseInt(items[3])).getBytes(enc));
97
- os.write(String.format("%02d", Integer.parseInt(items[4])).getBytes(enc));
98
+ os.write(String.format("%01d", Integer.parseInt(items[4])).getBytes(enc));
98
- os.write(String.format("%01d", Integer.parseInt(items[5])).getBytes(enc));
99
+ os.write(String.format("%07d", Integer.parseInt(items[5])).getBytes(enc));
99
- os.write(String.format("%07d", Integer.parseInt(items[6])).getBytes(enc));
100
+ os.write(String.format("%09d", Integer.parseInt(items[6])).getBytes(enc));
100
- os.write(String.format("%09d", Integer.parseInt(items[7])).getBytes(enc));
101
- os.write(String.format("%-100s", items[8]).getBytes(enc), 0, 32);
101
+ os.write(String.format("%-100s", items[7]).getBytes(enc), 0, 32);
102
102
 
103
103
  os.close();
104
104
 

3

変換後テキストファイルのカンマ削除

2023/04/20 05:06

投稿

moo1211
moo1211

スコア3

test CHANGED
File without changes
test CHANGED
@@ -15,8 +15,8 @@
15
15
  上記のようなCSVファイルをJavaで読み込み、テキストファイルに変換するプログラムを作っています。
16
16
  ```
17
17
  【変換後テキストファイル】
18
- "B",2023,01,22,1,1234567,000012345,"山田たろう           "
18
+ B2023012211234567000012345山田たろう           
19
- "B",2023,01,22,1,0123456,000001234,"佐藤けん            "
19
+ B2023012210123456000001234佐藤けん            
20
20
  ```
21
21
 
22
22
  ↓こちらの質問を参考にソースを作成しております。

2

返還前csvのレコード長変更

2023/04/20 05:05

投稿

moo1211
moo1211

スコア3

test CHANGED
File without changes
test CHANGED
@@ -8,15 +8,15 @@
8
8
 
9
9
  ```
10
10
  【変換前CSVファイル】
11
- "B",2023,01,22,1,1234567,000012345,"山田たろう           "
11
+ B,2023,1,22,1234567,12345,"山田たろう           "
12
- "B",2023,01,22,1,0123456,000001234,"佐藤けん            "
12
+ B,2023,1,22,123456,1234,"佐藤けん    "
13
13
  ```
14
14
 
15
15
  上記のようなCSVファイルをJavaで読み込み、テキストファイルに変換するプログラムを作っています。
16
16
  ```
17
17
  【変換後テキストファイル】
18
- B,2023,01,22,1234567,12345,"山田たろう           "
18
+ "B",2023,01,22,1,1234567,000012345,"山田たろう           "
19
- B,2023,01,22,123456,1234,"佐藤けん    "
19
+ "B",2023,01,22,1,0123456,000001234,"佐藤けん            "
20
20
  ```
21
21
 
22
22
  ↓こちらの質問を参考にソースを作成しております。

1

更新後csvデータのレコード長変更

2023/04/20 05:04

投稿

moo1211
moo1211

スコア3

test CHANGED
File without changes
test CHANGED
@@ -8,8 +8,8 @@
8
8
 
9
9
  ```
10
10
  【変換前CSVファイル】
11
- "B",2023,1,22,1,1234567,12345,"山田たろう           "
11
+ "B",2023,01,22,1,1234567,000012345,"山田たろう           "
12
- "B",2023,1,22,1,123456,1234,"佐藤けん    "
12
+ "B",2023,01,22,1,0123456,000001234,"佐藤けん            "
13
13
  ```
14
14
 
15
15
  上記のようなCSVファイルをJavaで読み込み、テキストファイルに変換するプログラムを作っています。