Read a text file before knowing the encoding
Hi,
I've wrote a AppleScript to adjust time delay of *.lrc file(txt file but different extension).I only got a messed up text, in other aspect, it works well. I understand applescript read the text file using the wrong encoding, but I can't just set the encoding to UTF-8, for it can be UTF-8 and it can be Shift-JIS, Big5 andGB18030 as well. I don't know how to open text without getting messed up and write the result to a new text file on desktop using UTF-8 encoding. Can anyone help me with this? Thanks in advance.
Code:
on run
set _lrcFile to (choose file)'s POSIX path
display dialog "Time to delay (sec):" with title "Adjust LRC Delay" default answer "-0.5"
set _timeDelay to text returned of result
try
set _timeDelay to _timeDelay as real
on error
display dialog "Input must be a real" with title "Error" buttons {"Stop"} default button "Stop"
error number -128
end try
set _paraList to paragraphs of (read POSIX file _lrcFile)-->I don't know how to read text file properly here.
set _newLrc to ""
repeat with _para in _paraList
set _timecode to do shell script "sed 's/\\[\\([0-9]\\{2\\}\\):\\([0-9]\\{2\\}.[0-9]\\{2\\}\\)\\]\\(.*\\)/\\1 \\2/'<<<" & quoted form of _para
if _timecode as string is not (contents of _para) then
set _timecode to words of _timecode
set _min to (item 1 of _timecode) as integer
set _sec to (item 2 of _timecode) as real
set _sec to _sec + _timeDelay
set _min to _min + _sec div 60
set _sec to _sec mod 60
set _sec to (round (_sec * 100)) / 100
if _min < 10 then
set _min to "0" & _min as string
else
set _min to _min as string
end if
if _sec < 0 then
set _sec to "00.00"
else if _sec < 10 then
set _sec to "0" & _sec as string
else
set _sec to _sec as string
end if
if (count of _sec) < 5 then
set _sec to _sec & "0"
end if
set _lyrics to do shell script "sed 's/\\[\\([0-9]\\{2\\}\\):\\([0-9]\\{2\\}.[0-9]\\{2\\}\\)\\]\\(.*\\)/\\3/'<<<" & quoted form of _para
set _newLrc to _newLrc & "[" & _min & ":" & _sec & "]" & _lyrics & return
else
set _newLrc to _newLrc & contents of _para & return
end if
end repeat
-->write _newLrc to destop here (using UTF-8 encoding)
end run
Sample of *.lrc and the result after delaying 0.5s.
Hope this post will help people doing their homeworks...
StringBuffer tmpBuffer = new StringBuffer();
try {
URL url = new URL("http://.../test.txt");
URLConnection urlconnection = url.openConnection();
long l = urlconnection.getContentLength();
tmpBuffer.append("Content Length = " + l);
BufferedReader in =
new BufferedReader(new InputStreamReader(url.openStream()));
String line;
while ((line = in.readLine()) != null) {
tmpBuffer.append("\n" + line);
in.close();
} catch (Exception e) {
//System.out.println(e.toString());
if (tmpBuffer != null) {
wdContext.currentContextElement().setZoneMessage(
tmpBuffer.toString());
Similar Messages
-
The program doest enterpret my figures from the text file in the correct way since the numbers contain dots instead of commas. Is there a way to fix this in labVIEW, or do I have to change the files before reading them in the program? Thanks beforehend!
You must go in the labview option menu, you can select 'use the local
separator' in the front side submenu (LV6i).
If you use the "From Exponential/Fract/Eng" vi, you are able to select this
opton (with a boolean) without changing the labview parameters.
(sorry for my english)
Lange Jerome
FRANCE
"Nina" a ecrit dans le message news:
[email protected]..
> I would like to read a text file in which the decimal numbers are
> using dots instead of commas. Is there a way of converting this in
> labVIEW, or how can I get the program to enterpret the figures in the
> correct way?
>
> The program doest enterpret my figures from the text file in the
> correct way since the numbers contain dots instea
d of commas. Is there
> a way to fix this in labVIEW, or do I have to change the files before
> reading them in the program? Thanks beforehend! -
Issue : Read a text file and print the same
Hi, My requirement is to read a text file and print it the same way.
import java.io.BufferedReader;
import java.io.FileReader;
public class CatFile {
public static void main(String[] args) throws Exception
FileReader file = new FileReader("D:/Test/Allfiles.txt");
BufferedReader reader = new BufferedReader(file);
String text = "";
String line = reader.readLine();
while (line != null)
text += line;
line = reader.readLine();
System.out.println(text);
The text file i used contains
A
B
C
but my output is ABC.
What change should be made to print it the same way in the txt file ?Hi EJP,
I modified the code based on your suggestion and now its working as expected. Thanks
Modified code :
import java.io.BufferedReader;
import java.io.FileReader;
public class CatFile {
public static void main(String[] args) throws Exception
FileReader file = new FileReader("D:/Test/Allfiles.txt");
BufferedReader reader = new BufferedReader(file);
String text = "";
String line = reader.readLine();
while (line != null)
System.out.println(line);
line = reader.readLine();
text += line;
} -
Reading text files without specifying the encoding?
I have looked everywhere for a solution, but I can't find one. The problem is that I'm using codes that everybody is using, but for some reason, my codes aren't working.
I want to be able to open up text files in Java without having to specify the encoding for the files that I'm going read, because I have no idea which encoding they will use.
But even when specifying UTF-8 to be encoding of the file to read, it doesn't work correctly:
FileInputStream fileIS= new FileInputStream("somefile.txt");
Reader reader = new BufferedReader(new InputStreamReader(fileIS, Charset.forName("UTF-8")));
EVERYWHERE I look, ppl are using these codes! But it doesn't work, some characters (such as the Euro sign) are displayed as squares.
However, I want to be able to read not only UTF-8 files but anything that Java supports. Any ideas?
Edited by: Stalfos on Oct 22, 2007 12:22 PMStalfos wrote:
I want to be able to open up text files in Java without having to specify the encoding for the files that I'm going read, because I have no idea which encoding they will use.
This is your problem. If you don't know what encoding the text is stored in, then the chances that the default encoding used to read it will be correct are slim.
But even when specifying UTF-8 to be encoding of the file to read, it doesn't work correctly:There are many different character encodings, and most of them don't overlap. Anything above 127 usually causes problems.
FileInputStream fileIS= new FileInputStream("somefile.txt");
Reader reader = new BufferedReader(new InputStreamReader(fileIS, Charset.forName("UTF-8")));
EVERYWHERE I look, ppl are using these codes! But it doesn't work, some characters (such as the Euro sign) are displayed as squares.The problem isn't with the code, it's that the file you're reading isn't using an encoding that's compatible with UTF-8. Assuming that using UTF-8 should work for all encodings is like assuming that someone who can read Chinese should be able to read a book written in Spanish or Greek. It doesn't work that way.
However, I want to be able to read not only UTF-8 files but anything that Java supports. Any ideas?You need to know what encoding your files are stored in, period. There are a few ways to guess what the encoding is, but they're only reliable for a small set of encodings.
You don't seem to truly understand what character encodings are, or how to use them, so read this:
The Absolute Minimum Every Software Developer Absolutely, Positively Must Know About Unicode and Character Sets (No Excuses!)
http://www.joelonsoftware.com/articles/Unicode.html -
Read a text file and put the text in a TextEdit UI
I have found code sample for reading file inside webdynpro, but I can't manage to make it works with a text file on the web (ex.: "http:/.../file.txt").
Can someone post the exact code needed for that?
Thanks!Hope this post will help people doing their homeworks...
StringBuffer tmpBuffer = new StringBuffer();
try {
URL url = new URL("http://.../test.txt");
URLConnection urlconnection = url.openConnection();
long l = urlconnection.getContentLength();
tmpBuffer.append("Content Length = " + l);
BufferedReader in =
new BufferedReader(new InputStreamReader(url.openStream()));
String line;
while ((line = in.readLine()) != null) {
tmpBuffer.append("\n" + line);
in.close();
} catch (Exception e) {
//System.out.println(e.toString());
if (tmpBuffer != null) {
wdContext.currentContextElement().setZoneMessage(
tmpBuffer.toString()); -
'read from text file' erases the file
I am trying to read text in from a text file. This is the exact code I am using. For some reason the output from 'read from text file' contains all the text that was originally in the file, but after the code executes the file is empty. I have several other vi's which use the same code and the file is fine. But whenever I run this code in this one specific vi the text file gets erased.
What is in the rest of that "specific vi"? I just tried the code you show, in v2011, and it works as expected, doesn't clear file.
What version are you running? Can you add an error out, or make sure error output is on in your LabVIEW configuration?
Putnam
Certified LabVIEW Developer
Senior Test Engineer
Currently using LV 6.1-LabVIEW 2012, RT8.5
LabVIEW Champion -
How can i read the text files and buffer the data in Vector?
hi. I have been running into this problem for days, but with no luck and losing right direction.
The problem is : I am trying to read a text file and buffer the data into a
Queue for each user.
the sample text file is as below:( 1st column is timestamp, 2nd is user_id, 3rd is packet_id, 4th is packet_seqno, 5th is packet_size)
0 1 1 1 512
1 2 1 2 512
2 3 1 3 512
3 4 1 4 512
4 5 1 5 512
5 6 1 6 512
6 7 1 7 512
7 8 1 8 512
8 9 1 9 512
9 10 1 10 512
10 1 2 11 512
11 2 2 12 512
12 3 2 13 512
13 4 2 14 512
14 5 2 15 512
15 6 2 16 512
16 7 2 17 512
17 8 2 18 512
18 9 2 19 512
19 10 2 20 512
20 1 3 21 512
21 2 3 22 512
22 3 3 23 512
23 4 3 24 512
24 5 3 25 512
25 6 3 26 512
26 7 3 27 512
27 8 3 28 512
28 9 3 29 512
29 10 3 30 512
30 1 4 31 512
31 2 4 32 512
32 3 4 33 512
33 4 4 34 512
34 5 4 35 512
35 6 4 36 512
36 7 4 37 512
37 8 4 38 512
38 9 4 39 512
39 10 4 40 512
40 1 5 41 512
41 2 5 42 512
42 3 5 43 512
43 4 5 44 512
44 5 5 45 512
45 6 5 46 512
46 7 5 47 512
47 8 5 48 512
48 9 5 49 512
49 10 5 50 512
50 1 6 51 512
51 2 6 52 512
52 3 6 53 512
53 4 6 54 512
54 5 6 55 512
55 6 6 56 512
56 7 6 57 512
57 8 6 58 512
58 9 6 59 512
59 10 6 60 512
60 1 7 61 512
61 2 7 62 512
62 3 7 63 512
63 4 7 64 512
64 5 7 65 512
65 6 7 66 512
66 7 7 67 512
67 8 7 68 512
68 9 7 69 512
69 10 7 70 512
70 1 8 71 512
71 2 8 72 512
What I wanna do is to read all the data above and buffer them in a queue for each user( there are only 10 users in total).
I already created a class called Class packet:
public class packet {
private int timestamp;
private int user_id;
private int packet_id;
private int packet_seqno;
private int packet_size;
/** Creates a new instance of packet */
public packet(int timestamp,int user_id, int packet_id,int packet_seqno, int packet_size)
this.timestamp = timestamp;
this.user_id=user_id;
this.packet_id=packet_id;
this.packet_seqno=packet_seqno;
this.packet_size=packet_size;
}then I wanna to create another Class called Class user which I can create a queue for each user (10 users in total) to store type packet information. the queue for each user will be in the order by timestamp.
any idea and sample code will be appreciated.Doesn't sound too hard to me. Your class User (the convention says to capitalize class names) will have an ArrayList or Vector in it to represent the queue, and a method to store a Packet object into the List. An array or ArrayList or Vector will hold the 10 user objects. You will find the right user object from packet.user_id and call the method.
Please try to write some code yourself. You won't learn anything from having someone else write it for you. Look at sample code using ArrayList and Vector, there's plenty out there. Post in the forum again if your code turns out not to behave. -
Trying to parse a file-read from text file.vi
I'm attempting to read a txt file that has tab separated data. In the fourth (or any) column is the only data I need. The data is a string of numbers (23.454).
I've used the Read from Text File.vi and the Read From Spreadsheet.vi and I just don't seem to have enough LV background to extract the pertinent data into a graph. any suggestions?(It is silly to use "delete from array" if all you want is a column. The correct function is "index array")
Joe's idea above basically works fine. Here's a quick adapdation (the node before the graph is "index array" from the array palette.).
Message Edited by altenbach on 06-11-2007 11:57 AM
LabVIEW Champion . Do more with less code and in less time .
Attachments:
FileRead.png 11 KB -
Read from Text File - Help Bug?
Hi - I am currently working on LV8 and I think that there is some misunderstanding potential in the help file. To be more exact in the help to the "Read From Text File" VI.
The description for "count":
" ... If count is <0, the function reads the entire file. The
default is –1, which indicates to read a single line if you placed a checkmark
next to the Read Lines shortcut menu item and to read the
entire file if you removed the checkmark next to the item. "
If count is lower than zero, the function reads the entire file. That sounds clear to me.
The default is -1, which indicates to read a single line if you placed a checkmark next to the "Read Lines" shortcut menu item. Now what? Does it read a single line or the whole file?
.. and to read the entire file if you removed the checkmark next to the item. I thought it reads the whole file if I use -1 ?
the VI itself behaves as I'd expect it to:
* If I place a checkmark next to Read Lines and put -1, I get an array containing the lines
* If I remove the checkmark, I get only a single string item.
Now where is the error? Is the VI not working properly or only the description a little bit ... strange ??hein??
?what?
Both you guys lost me..
And I drink coffee without sugar (being sweet enough, already)
Here is what I get from Context Help on the Read From Text File:
Read from Text File
Reads a specified number of characters or lines from a byte stream file. By default, this function reads all characters from the text file. Wire an integer value to count to specify how many individual characters you want to read starting with the first character. Right-click the function and place a checkmark next to the Read Lines option in the shortcut menu to read individual lines from the text file. When you select the Read Lines option in the shortcut menu, wire an integer value to the count input to specify how many individual lines you want to read from the file starting with the first line. Enter a value of -1 in count to read all characters and lines from the text file.
Humm.
New feature (again).. If you select checkmark the Read Lines option, it will not send the text to a sting indicator, as shown in the attached image. If selected, then it's expecting to write lines to an array of strings... WHY??? I don't know.. I'll ask..
Strange... LV8 is full of mysteries...
RayR
Attachments:
bad write file.JPG 33 KB
more bad write file.JPG 12 KB -
From an Oracle form, I want to read a text file.
From an Oracle form, I want to read a text file. In the form on a button press I have:
declare
in_file Text_IO.File_Type;
linebuf VARCHAR2(1800);
filename VARCHAR2(30);
BEGIN
filename:=GET_FILE_NAME('U:\ora_devl\pps\work\a.txt', File_Filter=>'Text Files (*.txt)|*.txt|');
in_file := Text_IO.Fopen(filename, 'r');
LOOP
Text_IO.Get_Line(in_file, linebuf);
-- :text_item5:=:text_item5||linebuf||chr(10);
Text_IO.New_Line;
END LOOP;
EXCEPTION
WHEN no_data_found THEN
Text_IO.Put_Line('Closing the file...');
Text_IO.Fclose(in_file);
END;
It gets an ORA-302000. I suspect the problem starts with the GET_FILE_NAME because when I comment out everything but that, It processes endlessly never ending.
Forms [32 Bit] Version 11.1.1.3.0 (Production)
Oracle Database 11g Enterprise Edition Release 11.2.0.1.0 - 64bit Production
What can you tell me? ThanksGET_FILE_NAME will try to open an "Open File" dialog on the server, which obviously can't happen. If you want to use that type of behavior you need to use WebUtil and the function CLIENT_GET_FILE_NAME. Example:
filename := CLIENT_GET_FILE_NAME('C:\', File_Filter=> 'Text Files (*.txt)|*.txt|All Files (*.*)|*.*|', dialog_type=> OPEN_FILE);Refer to the Builder Online help for more details. You can also refer to the demo which is available here:
http://www.oracle.com/technetwork/developer-tools/forms/downloads/index.html
More information here:
http://www.oracle.com/technetwork/developer-tools/forms/webutil-090641.html
Also, it appears that you are attempting to use a mapped drive ("U"). Although this can be made to work, it is not recommended and in some cases will not be supported. If you need access to remote files, you should use some other mechanism to bring the file to the local machine before manipulating it. -
Read multiple text files and sort them
I am trying to read multiple text files and store the data from the file in vector.
but for days. I am with no luck. anyone can help me out with it? any idea of how to sort them will be appreciated.
Below is part of the code I implemented.
public class packet {
private int timestamp;
private int user_id;
private int packet_id;
private int packet_seqno;
private int packet_size;
public packet(int timestamp0,int user_id0, int packet_id0,int packet_seqno0, int packet_size0)
timestamp = timestamp0;
user_id=user_id0;
packet_id=packet_id0;
packet_seqno=packet_seqno0;
packet_size=packet_size0;
public void setTime(int atimestamp)
this.timestamp=atimestamp;
public void setUserid(int auserid)
this.user_id=auserid;
public void setPacketid(int apacketid)
this.packet_id=apacketid;
public void setPacketseqno(int apacketseqno)
this.packet_seqno=apacketseqno;
public void setPacketsize(int apacketsize)
this.packet_size=apacketsize;
public String toString()
return timestamp+"\t"+user_id+"\t"+packet_id+"\t"+packet_seqno+"\t"+packet_size+"\t";
}Here is the data from part of the text files. ( the first column is timestamp, second is userid, third is packetid.....)
0 1 1 1 512
1 2 1 2 512
2 3 1 3 512
3 4 1 4 512
4 5 1 5 512
5 6 1 6 512
6 7 1 7 512
7 8 1 8 512
8 9 1 9 512
9 10 1 10 512
10 1 2 11 512
11 2 2 12 512
12 3 2 13 512
13 4 2 14 512
14 5 2 15 512
15 6 2 16 512
16 7 2 17 512Here's a standard idiom for object-list-sorting:
/* cnleafdata.txt *********************************************
0 1 1 1 512
1 2 1 2 512
2 3 1 3 512
3 4 1 4 512
4 5 1 5 512
5 6 1 6 512
6 7 1 7 512
7 8 1 8 512
8 9 1 9 512
9 10 1 10 512
10 1 2 11 512
11 2 2 12 512
12 3 2 13 512
13 4 2 14 512
14 5 2 15 512
15 6 2 16 512
16 7 2 17 512
import java.util.*;
import java.io.*;
public class Packet implements Comparable<Packet>{
private int timeStamp;
private int userId;
private int packetId;
private int packetSeqno;
private int packetSize;
public Packet(int timeStamp0, int userId0, int packetId0,
int packetSeqno0, int packetSize0) {
timeStamp = timeStamp0;
userId = userId0;
packetId = packetId0;
packetSeqno = packetSeqno0;
packetSize = packetSize0;
public Packet(String timeStamp0, String userId0, String packetId0,
String packetSeqno0, String packetSize0) {
this(Integer.parseInt(timeStamp0), Integer.parseInt(userId0),
Integer.parseInt(packetId0), Integer.parseInt(packetSeqno0),
Integer.parseInt(packetSize0));
public Packet(String[] a){
this(a[0], a[1], a[2], a[3], a[4]);
public void setTime(int aTimeStamp){
timeStamp = aTimeStamp;
public void setUserId(int aUserId){
userId = aUserId;
public void setPacketId(int aPacketId){
packetId = aPacketId;
public void setPacketSeqno(int aPacketSeqno){
packetSeqno = aPacketSeqno;
public void setPacketSize(int aPacketSize){
packetSize = aPacketSize;
public int getUserId(){
return userId;
public String toString(){
return String.format
("%2d %2d %2d %2d %4d", timeStamp, userId, packetId, packetSeqno, packetSize);
public int compareTo(Packet otherPacket){
return userId - otherPacket.getUserId();
/* main for test */
public static void main(String[] args){
String line;
ArrayList<Packet> alp;
alp = new ArrayList<Packet>();
try{
BufferedReader br = new BufferedReader(new FileReader("cnleafdata.txt"));
while ((line = br.readLine()) != null){
// if (! recordValid(line)){
// continue;
String[] ar = line.split("\\s");
alp.add(new Packet(ar));
catch (Exception e){
e.printStackTrace();
System.out.println("[original]");
for (Packet p : alp){
System.out.println(p);
System.out.println();
Collections.sort(alp);
System.out.println("[sorted by user ID]");
for (Packet p : alp){
System.out.println(p);
} -
Reading a text file and putting it in a textarea
hi can u tell me how to read a text file and display the contents in a text area using jsp please?
thanks :o)<%@ page import="java.sql.*, java.io.*" %>
<HTML>
<HEAD>
<TITLE>User Application Area</TITLE>
<SCRIPT LANGUAGE="javascript" SRC="cal2.js">
</SCRIPT>
<SCRIPT LANGUAGE="javascript" SRC="cal_conf2.js"></SCRIPT>
</HEAD>
<BODY BGCOLOR="#FFFFFF" TEXT="#000000">
<%
Class.forName("sun.jdbc.odbc.JdbcOdbcDriver");
Connection con = DriverManager.getConnection("jdbc:odbc:fypproject","","");
Statement st = con.createStatement();
String email = (String)session.getAttribute("email");
String levelStatus = (String)session.getAttribute("levelStatus");
String details = "SELECT PD.Forename, PD.Surname, L.Level_Name FROM Personal_Details PD,
Login_Details LD, Levels L WHERE PD.Email_Address = '" + email + "' AND PD.Email_Address =
LD.Email_Address AND LD.Level_ID = '" + levelStatus + "' AND LD.Level_ID = L.Level_ID";
ResultSet rsDet = st.executeQuery(details);
if(rsDet.next()) {
String forename = rsDet.getString("Forename");
String surname = rsDet.getString("Surname");
String levelName = rsDet.getString("Level_Name");
%>
<DIV ALIGN="center"><H1>User Application Arena</H1></DIV>
<BR>
<H4>Welcome back <% out.println(forename + " " + surname); %> </H4>
<BR>
Your status is:
<FONT COLOR = "red">
<% out.println(levelName); %>
</FONT>
<BR>
<%
if(levelStatus.compareTo("0")==0) {
%>
<BR>
<DIV ALIGN="center">
Please come back later and re-check your status to see if your application has progressed. If it has
been more than a week since you submitted it please phone the HR department on 020 7123 4567
<BR><BR>
Log Out
</DIV>
</FORM>
<%
else if(levelStatus.compareTo("1")==0) {
%>
<FORM NAME="sampleform" ACTION="ProcessInterview.jsp">
<DIV ALIGN="center">
Congratulations, we would like to invite you for a First Round tests and interview. Please select a
date that would suit you on our online calendar below
<BR><BR>
<SMALL>PLEASE CLICK HERE TO SELECT A DATE</SMALL>
<BR><BR>
<INPUT TYPE="text" NAME="firstinput" SIZE=20>
<BR><BR>
<INPUT TYPE="submit" VALUE="Confirm">
</DIV>
</FORM>
<%
else if(levelStatus.compareTo("2")==0) {
%>
<FORM NAME="sampleform" ACTION="ProcessInterview.jsp">
<DIV ALIGN="center">
Congratulations, we would like to invite you for a Second Round interview. Please select a date that
would suit you on our online calendar below
<BR><BR>
<SMALL>PLEASE CLICK HERE TO SELECT A DATE</SMALL>
<BR><BR>
<INPUT TYPE="text" NAME="firstinput" SIZE=20>
<BR><BR>
<INPUT TYPE="submit" VALUE="Confirm">
</DIV>
</FORM>
<%
else if(levelStatus.compareTo("3")==0) {
File inFile = new File("offer.txt");
StringBuffer sb = new StringBuffer();
BufferedReader buf = new BufferedReader(new FileReader(inFile));
while (buf.ready()) {
sb.append(buf.readLine());
buf.close();
%>
<TEXTAREA NAME ="text" ROWS="10" COLS="60">
<%= sb.toString() %>
</TEXTAREA>
<%
else if(levelStatus.compareTo("4")==0) {
out.println("send rej email");
st.close();
con.close();
%>
</BODY>
</HTML>
THANKS!! :o) -
I am running an Air App I did for the desktop, from the actual installed executable already deployed in the machine (Not from Flash Pro / Flex dev. environment). For some reason the app will not read a text file stored in the same application folder unless I run my app as administrator from the OS.
When I run the app as admin, or within the development environment it works fine. Maybe this is related to some security issue? I read the adobe air documentation, and this should work...
I am using openAsync/readUTFBytes on user as shown here:
var continueGamesConnection:FileStream();
var continueFile:File = new File(File.applicationDirectory.resolvePath("continueGames.txt").nativePath.toString());
continueGamesConnection.addEventListener(Event.COMPLETE, openSavedGames);
continueGamesConnection.openAsync(continueFile, FileMode.UPDATE);
function openSavedGames(event:Event):void
continueGamesConnection.removeEventListener(Event.COMPLETE, openSavedGames);
var content:URLVariables = new URLVariables();
var loadedContent:String = new String();
loadedContent = continueGamesConnection.readUTFBytes(continueGamesConnection.bytesAvailable);
content.decode(loadedContent);
variableX = content. variableX
//etc, etc.
continueGamesConnection.close();
By the way, I have also, tried using FileMode.READ, and others, and it still gives me the same problem. Only works if ran on admin mode or from the dev. environment.
It's very frustrating, I tried reading other posts without any luck... What solutions do people use for this kind of problem?
I have seen that you can set the app to run as admin somehow, and I guess that could work. However, this should work just fine, since it doesn't seem to violate any of the security APIs of Air. Seems like an overkill. But even so, how do I do that?
You help is greatly appreciated!Thanks kglad.com. I will try this and see if it works. Can you check my code a bit to see if it's right?
var continueFile:File = new File(File.applicationStorageDirectory.resolvePath("savedgames/continueGames.txt").nativePath.toString());
Does this look right to work across all desktop OS? -
Is it possible in to know the encoding of file ?
Hi All,
I want to know the encoding of the text file before I use.
Is it possible in to know the encoding of file ?
Do we have any meta attributes of the file that describes its encoding ?
Thanks & Regards
Balaji ChopparapuGenerally speaking: no, you're out of luck.
Sometimes you can guess the encoding by analyzing the file (UTF-8 can be detected like this, different versions of ISO-8859-* are much harder to distinguish this way).
Some file formats (most notably XML) provide a way to find out the encoding of the file (provided the application writing it was conforming to the rules).
Can you describe what kind of files you want to read, where they come from and what you want to do with them? -
How to know they is space or carrier return when java read a text file.
Hi,
Please help.
How to know they is space or carrier return when java read a text file.
The reason is that. I want to use java for loop to read each part of value. for example: first part is the items name. After the space (I need to tell java when this is a space here and its need to skip) , following by the items prices in double value and space again (need to skip also) and etc.
item name1
item name2
item name3
item name4
item name5
<--- here is the space to skip and another loop to read following items prices
item price1
item price2
item price3
item price4
item price5
<--- here is another spcae again. and so on
thank in advance!You can check to see if the sting you read in is just nothing, depending on how you're reading it in:
if((str = inStream.readLine().trim().equals("")))
// skip and get ready for the next section
else
// handle the next item
The trim() method gets rid of all leading and trailing spaces and I'm assuming you're using a stream that can use the readLine() method that returns a String.
I hope this is clear. Let me know if it isn't, I'll try and word it different, or post how you're reading the values in if you need more help.
Maybe you are looking for
-
Tab 7.0 Update Issues / Findings
* Update Notice received/Performed 11/3 @ 9:30pm - Had two browser windows active, something already in 'Copy' memory, went to Copy again and it closed all the browser windows - Scrolling is smoother but alittle more touchy. If a web page has an em
-
How to include a html file in jsp
hi all I have a question about including a html in jsp. here's the sample of my jsp file: <% String filename = "helloworld.html"; %> <%@ include file="helloworld.html" %> how will you go about doing it so that the included file depends on the variabl
-
Vendor Payment has been done without doing MIRO Postings
Hi, In the SAP system, Goods receipt has been done (MIGO) with respect to a Purchase order for the period of March 2009 fiscal year. Now FI user has made the direct payment to the vendor in April period of 2010 fiscal year for the qty. received witho
-
How to store an array in a session
hi everyone iam getting problem while storing an arrray in a session can any one help me thanks in advance
-
LinkedButton and lf_Employee
Hi all, I create a linkButton and a edit text. I'm link the button to lF_Employee and to the Edit Text. The link doesn't work, i can't open the form associate at the name of the edit text. If i insert the name or the empID, nothing happends. The butt