text-files

Importing a txt file when number of columns varies?

耗尽温柔 提交于 2019-12-01 01:17:44
问题 I have problems importing a .txt file into R because the number columns changes from eight to nine. Initially, my data has eight columns: Date, Open, High, Low, Close, Volume, Open Interest, Delivery Month Later, I add an additional column Unadjusted close . How should I import the data? Somehow the Unadjusted close column has to be ignored at the beginning. I've tried data1 <- read.table("AD_0.TXT", sep=",", header=TRUE) but that doesn't work. 回答1: You need to use the fill argument in the

Android read text file from internet

老子叫甜甜 提交于 2019-12-01 00:54:18
I want to read a remote text file and show its content in a textview. I have written this below code, but it doesn't get any information from the text file. How can I find the reason of this problem or solve it? isn't there anything wrong in my code? private void readFile() { try { String path ="http://host.com/info.txt"; URL u = new URL(path); HttpURLConnection c = (HttpURLConnection) u.openConnection(); c.setRequestMethod("GET"); c.setDoOutput(true); c.connect(); InputStream in = c.getInputStream(); Log.e("value",in.toString()); AssetManager mngr=getAssets(); ByteArrayOutputStream bo = new

Pulling data from SQL, and writing to a text file

…衆ロ難τιáo~ 提交于 2019-12-01 00:47:50
I am trying to pull data from SQL, and then write it to a text file. This does that, to an extent, but it only pulls 1 from the table, which reads test:test<br> on the text file. I want to be able to pull all the data from the table, and then post to the text file in a list format such as this... test:test test2:test2 test3:test3 I need to find out what I am doing wrong. <?php $sql = mysql_query("SELECT * FROM _$setprofile ORDER BY fc DESC"); while($row = mysql_fetch_array($sql)){ $user = $row['user']; $pass = $row['pass']; $accounts = "$user:$pass<br>"; //Functionsss! $file = "backups/

OutputStreamWriter does not append

自作多情 提交于 2019-12-01 00:45:37
问题 Original code and its working saving the data to the SD Card // Writing data to internal storage btnSaveData.setOnClickListener(new View.OnClickListener() { @Override public void onClick(View v) { if (isSDCardWritable()) { String dataToSave = etData.getText().toString(); try { // SD Card Storage File sdCard = Environment.getExternalStorageDirectory(); File directory = new File(sdCard.getAbsolutePath()+"/MyFiles"); directory.mkdirs(); File file = new File(directory, "text.txt");

Unix one-liner to swap/transpose two lines in multiple text files?

最后都变了- 提交于 2019-12-01 00:24:57
I wish to swap or transpose pairs of lines according to their line-numbers (e.g., switching the positions of lines 10 and 15) in multiple text files using a UNIX tool such as sed or awk. For example, I believe this sed command should swap lines 14 and 26 in a single file: sed -n '14p' infile_name > outfile_name sed -n '26p' infile_name >> outfile_name How can this be extended to work on multiple files? Any one-liner solutions welcome. This might work for you (GNU sed): sed -ri '10,15!b;10h;10!H;15!d;x;s/^([^\n]*)(.*\n)(.*)/\3\2\1/' f1 f2 fn This stores a range of lines in the hold space and

Searching for string within a text file in R [closed]

房东的猫 提交于 2019-11-30 22:53:37
Is there an R function that would search for s string within a text file? Something like unix grep? I guess the alternative will be to read the file line by line but was wondering if that can be bypassed by such a function? 1) Read it in and use R's grep : # test input cat("a 1\n\b 2\nc 3\n", file = "myfile.dat") grep("a", readLines("myfile.dat"), value = TRUE) ## [1] "a 1" 2) Another possibility if you have grep on your system and on the search path is: shell("grep a myfile.dat") ## a 1 On Windows you could use findstr in place of grep or if you have Rtools installed but not on your path

When downloading a file from ASP .Net, the text file gets appended with HTML content

旧街凉风 提交于 2019-11-30 21:32:25
I have made a page that allows users to upload files to the server using a FileUpload Control and handling its event with this code Sub SaveAttachment() Dim root As String = "C:\temp\" Dim filename As String = FileUpload1.FileName Dim SaveName As String = root & filename FileUpload1.SaveAs(SaveName) End Sub That worked fine, I was able to see files getting uploaded, and the content of the files is intact (exactly a duplicate copy of the file that the user's upload). Now for downloading the files back to the user (at a later time) I have written another page that reads the file name from a

Pulling data from SQL, and writing to a text file

时光毁灭记忆、已成空白 提交于 2019-11-30 19:55:32
问题 I am trying to pull data from SQL, and then write it to a text file. This does that, to an extent, but it only pulls 1 from the table, which reads test:test<br> on the text file. I want to be able to pull all the data from the table, and then post to the text file in a list format such as this... test:test test2:test2 test3:test3 I need to find out what I am doing wrong. <?php $sql = mysql_query("SELECT * FROM _$setprofile ORDER BY fc DESC"); while($row = mysql_fetch_array($sql)){ $user =

text file: Reading line by line C#

僤鯓⒐⒋嵵緔 提交于 2019-11-30 18:55:57
So, let's say i have a text file with 20 lines, with on each line different text. i want to be able to have a string that has the first line in it, but when i do NextLine(); i want it to be the next line. I tried this but it doesn't seem to work: string CurrentLine; int LastLineNumber; Void NextLine() { System.IO.StreamReader file = new System.IO.StreamReader("c:\\test.txt"); CurrentLine = file.ReadLine(LastLineNumber + 1); LastLineNumber++; } How would i be able to do this? Thanks in advance. In general, it would be better if you could design this in a way to leave your file open, and not try

How to read and write a text file in Flutter

这一生的挚爱 提交于 2019-11-30 18:34:28
问题 How do you read text from a file and write text to a file? I've been learning about how to read and write text to and from a file. I found another question about reading from assets, but that is not the same. I will add my answer below from what I learned from the documentation. 回答1: Setup Add the following plugin in pubspec.yaml : dependencies: path_provider: ^0.4.1 Update the version number to whatever is current. And import it in your code. import 'package:path_provider/path_provider.dart'