- Home /
Saving Data to Network Drive
In unity I can save data and files to:
--my C: drive (persistant path, documents folder)
--the internet (my web server, cloud service, sql (data only))
my current situation has me on a LAN and i need to save the data to a network drive so i can read and write to it when i am at a different stations.
How to save to a Network Drive? (assuming no internet and only a local network.) data vs files???
NOTE: if your response is it is not possible, then just don't respond because you are shutting down conversation for possible solutions.
Please only provide constructive responses, that work towards a solution for the given setting.
Answer by dee7800 · Mar 30, 2020 at 05:55 AM
i found a solution on my own
working form this post
you can utilize: "using System.IO;"
then you can call the functions:
File.WriteAllText(x1,x2)
and
File.ReadAllText(x1)
Below is my c# code for unity for a test save and read back:
////////////////////
// de boer shapes //
////////////////////
using System.Collections;
using System.Collections.Generic;
using UnityEngine;
using System.IO;
public class test_save : MonoBehaviour{
private string target="O:/test_target";
private string f_name="my_data_test.txt";
private string the_data= "de boer shapes\nwas here"+"\n\n\n"+
"write this data to a text file please\n"+
"save it on my network drive please\n"+
"combine with windows and raidrive and save to the cloud please"+
"\n\n\n"+"here was\nde boer shapes";
private bool save_failure=false;
private bool read_failure=false;
private string read_data="";
void Start(){
Debug.Log("target: "+target);
Debug.Log("f_name: "+f_name);
Debug.Log("the_data: "+the_data);
savedata2file(target, f_name, the_data);
Debug.Log("save success: "+!save_failure);
read_data=readfile2data(target, f_name);
Debug.Log("read success: "+!read_failure);
Debug.Log("read_data: "+read_data);
}
public void savedata2file(string _path, string _file_name, string _save_data){
try{
//create directory if needed
if(Directory.Exists(_path)==false){
Directory.CreateDirectory(_path);
}
//save the data
File.WriteAllText(_path+"/"+_file_name, _save_data);
}catch(System.Exception _error){
//save filaure
Debug.LogError("file save failed: "+_error);
save_failure=true;
}
}
public string readfile2data(string _path, string _file_name){
try{
//return data
return(File.ReadAllText(_path+"/"+_file_name));
}catch(System.Exception _error){
Debug.LogError("read file failed: "+_error);
read_failure=true;
//return empty string
return("");
}
}
}
////////////////////
// de boer shapes //
////////////////////
/* db
dbdbdbdbdbdbdbdbdb
db dbdb dbdb db
db dbdb dbdbdbdb dbdb db
dbdbdbdbdbdbdbdb dbdbdbdb dbdbdbdbdb dbdb db
dbdbdb dbdb dbdb dbdb dbdb dbdbdb dbdbdb db
dbdb dbdb dbdb dbdb dbdb dbdbdb dbdbdb
db dbdb dbdb dbdb dbdb dbdbdb dbdb
db dbdb dbdb dbdb dbdb dbdbdb
dbdbdb dbdb dbdb dbdb dbdbdb
dbdb dbdb dbdb dbdb dbdbdb
dbdb dbdb dbdb dbdb dbdb
dbdb dbdb dbdb dbdb
dbdb dbdb dbdb db
dbdb dbdb dbdb dbdb
dbdb dbdb dbdb dbdb
db dbdb dbdb dbdb
dbdb dbdb dbdb dbdb
dbdb dbdb dbdb dbdb db
dbdbdb dbdb dbdb dbdb dbdbdb
dbdbdb dbdb dbdb dbdb dbdbdb
dbdbdb dbdb dbdb dbdb dbdb db
dbdb dbdbdb dbdb dbdb dbdb dbdb db
dbdbdb dbdbdb dbdb dbdb dbdb dbdb dbdb
db dbdbdb dbdbdb dbdb dbdb dbdb dbdb dbdbdb
db dbdb dbdbdb dbdb dbdbdbdb dbdbdbdbdbdbdbdb
db dbdbdb dbdbdbdb dbdbdb db
db dbdb dbdbdb
dbdbdbdbdbdbdbdbdb
db */
Your answer
Follow this Question
Related Questions
check SQLite database record 1 Answer
Unity problem when i convert playerprefs save to the standard file io save 0 Answers
HLAPI - Old server messages sent on reconnect 0 Answers
Save Datasets at runtime 2 Answers
Save and load data via Facebook SDK 0 Answers