如何在 Windows Phone 8 中异步附加文件 [英] How to append a file, asynchronously in Windows Phone 8

查看:21
本文介绍了如何在 Windows Phone 8 中异步附加文件的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在尝试附加到最新 Windows Phone 中的文件.问题是我试图异步地做所有事情,但我不知道该怎么做.

I'm trying to append to a file in the latest Windows Phone. The problem is i'm trying to do everything asynchronously and i'm not sure how to do it.

    private async void writeResult(double lat, double lng)
    {

        StorageFolder localFolder = ApplicationData.Current.LocalFolder;
        StorageFile storageFile = await localFolder.CreateFileAsync("result.txt", CreationCollisionOption.OpenIfExists);
        Stream writeStream = await storageFile.OpenStreamForWriteAsync();
        using (StreamWriter writer = new StreamWriter(writeStream))
        //using (StreamWriter sw = new StreamWriter("result.txt", true))
        {
            {
                await writer.WriteLineAsync(lat + "," + lng);
                //await sw.WriteLineAsync(lat + "," + lng);
                writer.Close();
                //sw.Close();
            }
        }
    }

到目前为止我有这个,它可以很好地写入文件,我可以稍后读取它,但它会覆盖我拥有的内容而不是新行.注释掉的行显示了在 WP7 中没有流的情况下如何进行,但我也无法让它工作(事实是附加标志),无论如何确实应该使用新的 WP8 方法.

I have this so far, which writes to the file fine and I can read it later on much the same, however it writes over what I have instead of on a new line. The commented out lines show how to go about without the stream in WP7, but I can't get that to work either (the true is is the append flag) and really should be utilizing the new WP8 methods anyway.

感谢任何评论

推荐答案

我能够成功使用 Oleh Nechytailo 的建议 ( Stream.Seek() )

I was able to use the suggestion ( Stream.Seek() ) by Oleh Nechytailo successfully

这篇关于如何在 Windows Phone 8 中异步附加文件的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆