- Home /
How to save a text file in Windows 8
Here's how I usually save files
using (StreamWriter writer = new StreamWriter(GetDocumentsPath()+"/"+filename))
{
writer.Write("foo");
}
But yet again this code doesn't seem to be supported in Windows Phone/8. Does anyone know a way to do this?
Answer by $$anonymous$$ · Aug 24, 2013 at 03:45 PM
Try this:
using UnityEngine;
using System.Collections;
using System;
using System.IO;
using System.Text;
public class TxtSaver : MonoBehaviour {
String path;
String fileName;
// Use this for initialization
void Start ()
{
fileName = "/MyTxT.txt";//File name
}
// Update is called once per frame
void Update ()
{
path = Application.dataPath + fileName;//Path
using (FileStream fs = File.Create(path))
{
AddText(fs, "Text");//Text content
}
}
private static void AddText(FileStream fs, string value)
{
byte[] info = new UTF8Encoding(true).GetBytes(value);
fs.Write(info, 0, info.Length);
}
}
This works well for Windows Phone, but gives me the error:
The type or namespace name 'FileStream' does not exist in the namespace 'System.IO' when I try to build for Windows 8 Store
Answer by zezba9000 · Sep 13, 2013 at 07:15 AM
If you're looking for a plugin that can handle this on Win8 and WP8, iv'e made one you can find here: http://u3d.as/content/reign-studios/reign-win8-wp8-support-/5pH
Answer by alex107 · Oct 01, 2013 at 08:05 AM
I created a sample that enabled use of storage file, by using events and passing a stream back to the caller. https://www.dropbox.com/s/0thac2x5f36g2cp/IOTest.zip
Your answer
Follow this Question
Related Questions
how to take the finished file in unity ?and how to submit it to the store ? 1 Answer
Save GUI List to my Text File 0 Answers
IOS Serialization How To 1 Answer
Sharing Violation On Path 1 Answer
Access is denied in Windows 8 App 0 Answers