- Home /
Question by
$$anonymous$$ · Aug 22, 2013 at 01:36 PM ·
c#erroraccesstxt
Creating .txt file error
Im trying to making a .txt file but i have an error! I searched many of solutions but they didnt help, any ideas are appriciated! Thanks!
Code:
using UnityEngine;
using System.Collections;
using System;
using System.IO;
using System.Text;
public class TxtMaker : MonoBehaviour {
String path;
// Update is called once per frame
void Update ()
{
path = Application.dataPath;
Debug.Log(path);
using (FileStream fs = File.Create(path))
{
AddText(fs, "\r\n\r\nThe following is a subset of characters:\r\n");
}
}
private static void AddText(FileStream fs, string value)
{
byte[] info = new UTF8Encoding(true).GetBytes(value);
fs.Write(info, 0, info.Length);
}
}
Error :
UnauthorizedAccessException: Access to the path 'C:/Users/Valentin/Documents/New Unity Project/Assets' is denied.
Comment
Best Answer
Answer by $$anonymous$$ · Aug 22, 2013 at 01:46 PM
Fixed! I just needed to add filename to my path:
String fileName;
void Start()
{
fileName = "/MyTxT.txt";
}
void Update()
{
path = Application.dataPath + fileName;
}
Your answer
![](https://koobas.hobune.stream/wayback/20220613112737im_/https://answers.unity.com/themes/thub/images/avi.jpg)
Follow this Question
Related Questions
Accessing C# scripts from other objects 1 Answer
Multiple Cars not working 1 Answer
Distribute terrain in zones 3 Answers
Internal compiler error. 2 Answers
Sync with visual studio 2010 error 1 Answer