0
react-native-fsを使用してローカルファイルシステムからテキストファイルを読み取ろうとしています。ローカルファイルを読み込む
しかし、それはファイルが存在しないことを伝え続けます(私はそれをダブルチェックし、実行ウィンドウにコピーしようとしました)。
'use strict';
import React, { Component } from 'react';
//import FileSystem from 'react-native-filesystem';
import RNFS from 'react-native-fs';
import {
AppRegistry,
StyleSheet,
Text,
View,
NetInfo
} from 'react-native';
export default class FactsApiFetcher extends Component
{
constructor(props)
{
super(props);
this.state =
{
fact: 'Loading...'
}
}
componentWillMount()
{
this._getRandomFact();
}
_getRandomFact()
{
const fileContents = RNFS.read("D:\\AllRand\\facts-api-handler\\test.txt") //FileSystem.readFile("D:\\AllRand\\allfacts\\test.txt");
this.setState({
fact: fileContents
})
}
render()
{
return <Text> { this.state.fact } </Text>;
}
}
AppRegistry.registerComponent('FactsApiFetcher',() => FactsApiFetcher);
設定をしましたか? https://github.com/itinance/react-native-fs#usage-androidにあり、そこにも使用例があります。 –
ドキュメントhttps://github.com/itinance/react-native-fs#readfilepath-string-length--0-position--0-encodingoroptions-any-promisestringから、 'read(を使用すると約束を返す必要があります) ' –