문제

이 PCL 라이브러리의 새로운 기능이며, Xamarin과 iPhone 앱을 개발하고 전화로 저장하는 방법을 찾을 수 없습니다.가장 가까운 가장 가까운 것은 pclStorage와 함께 있지만 텍스트 만 저장합니다. 다른 절차와 함께 바이너리 파일을 저장할 수있는 또 다른 방법이 있습니다. 고맙습니다.

foreach (images element in json_object)
{
            //var nameFile = Path.Combine (directoryname, element.name);
            try{
                IFile file = await folder_new.GetFileAsync(element.name);
            }catch(FileNotFoundException ex ){
                RestClient _Client = new RestClient(element.root);
                RestRequest request_file = new RestRequest("/images/{FileName}");
                request_file.AddParameter("FileName", element.name, ParameterType.UrlSegment);
                _Client.ExecuteAsync<MemoryStream>(
                        request_file,
                        async Response =>
                        {
                                if (Response != null)
                                {
                                    IFolder rootFolder_new = FileSystem.Current.LocalStorage;
                                    IFile file_new = await rootFolder_new.CreateFileAsync(element.name,CreationCollisionOption.ReplaceExisting);
                                    await file_new.WriteAllTextAsync(Response.Data);
                                }
                        });
            }
        }
.

도움이 되었습니까?

해결책

ifile.openasync 메서드를 사용하여 2 진 데이터를 읽거나 쓰는 데 사용할 수있는 스트림을 가져옵니다.다음은 파일을 읽는 방법입니다.

IFile file = await folder_new.GetFileAsync(element.name);
using (Stream stream = await file.OpenAsync(FileAccess.Read))
{
    //  Read stream and process binary data from it...

}
.

라이센스 : CC-BY-SA ~와 함께 속성
제휴하지 않습니다 StackOverflow
scroll top