質問編集履歴
1
追記
test
CHANGED
File without changes
|
test
CHANGED
@@ -67,3 +67,125 @@
|
|
67
67
|
}
|
68
68
|
|
69
69
|
```
|
70
|
+
|
71
|
+
【追記】
|
72
|
+
|
73
|
+
外部テキストファイルへの書き出し・読み込み部分のコードです。
|
74
|
+
|
75
|
+
```ここに言語を入力
|
76
|
+
|
77
|
+
// 外部テキストファイルに保存
|
78
|
+
|
79
|
+
function hairetsuSave(){
|
80
|
+
|
81
|
+
var hairetsu = JSON.parse(localStorage.getItem('hairetsu')); // LocalStorageに保存した連想配列を読み込む
|
82
|
+
|
83
|
+
window.resolveLocalFileSystemURL('cdvfile://localhost/persistent/',
|
84
|
+
|
85
|
+
function(dir){
|
86
|
+
|
87
|
+
dir.getFile("hairetsu.txt", {create: true}, function (entry) {
|
88
|
+
|
89
|
+
entry.createWriter(function (writer) {
|
90
|
+
|
91
|
+
writer.write(hairetsu);
|
92
|
+
|
93
|
+
}, function (error) {
|
94
|
+
|
95
|
+
window.alert("書込失敗 :" + error.code + " - " + message);
|
96
|
+
|
97
|
+
});
|
98
|
+
|
99
|
+
}, function (error) {
|
100
|
+
|
101
|
+
window.alert("書込失敗 :" + error.code + " - " + message);
|
102
|
+
|
103
|
+
});
|
104
|
+
|
105
|
+
},
|
106
|
+
|
107
|
+
function(error){
|
108
|
+
|
109
|
+
window.alert("書込失敗 :" + error.code + " - " + message);
|
110
|
+
|
111
|
+
}
|
112
|
+
|
113
|
+
);
|
114
|
+
|
115
|
+
}
|
116
|
+
|
117
|
+
|
118
|
+
|
119
|
+
|
120
|
+
|
121
|
+
|
122
|
+
|
123
|
+
// 外部テキストファイルから読み込み
|
124
|
+
|
125
|
+
function hairetsuLoad() {
|
126
|
+
|
127
|
+
|
128
|
+
|
129
|
+
var filename = 'hairetsu.txt';
|
130
|
+
|
131
|
+
var folderurl = cordova.file.documentsDirectory;
|
132
|
+
|
133
|
+
|
134
|
+
|
135
|
+
window.resolveLocalFileSystemURL( folderurl ,
|
136
|
+
|
137
|
+
function getDirectoryEntry( directoryEntry ) {
|
138
|
+
|
139
|
+
directoryEntry.getFile( filename, null,
|
140
|
+
|
141
|
+
function readFile( fileEntry ) {
|
142
|
+
|
143
|
+
fileEntry.file(
|
144
|
+
|
145
|
+
function( file ) {
|
146
|
+
|
147
|
+
var reader = new FileReader();
|
148
|
+
|
149
|
+
reader.onloadend = function() {
|
150
|
+
|
151
|
+
|
152
|
+
|
153
|
+
alert("テキストファイルから読み込んだ配列: " + this.result); // this.result=連想配列、これが認識されない
|
154
|
+
|
155
|
+
|
156
|
+
|
157
|
+
displayFileData(fileEntry.fullPath + ": " + this.result);
|
158
|
+
|
159
|
+
};
|
160
|
+
|
161
|
+
reader.readAsText(file);
|
162
|
+
|
163
|
+
},
|
164
|
+
|
165
|
+
function fail(e) {
|
166
|
+
|
167
|
+
}
|
168
|
+
|
169
|
+
);
|
170
|
+
|
171
|
+
},
|
172
|
+
|
173
|
+
function fail(e) {
|
174
|
+
|
175
|
+
}
|
176
|
+
|
177
|
+
);
|
178
|
+
|
179
|
+
},
|
180
|
+
|
181
|
+
function fail(e) {
|
182
|
+
|
183
|
+
}
|
184
|
+
|
185
|
+
);
|
186
|
+
|
187
|
+
}
|
188
|
+
|
189
|
+
|
190
|
+
|
191
|
+
```
|